UE5 Pointer To Delegate As Class Variable

Table of Contents

You Cannot Set A Member Variable As A Pointer To A Delegate

Almost all the time, you want a reference to unreal engine delegates, not a copy. At this point you may have tried and attempted to do something like:

UPROPERTY()

FSomeDelegate* delegatePtr;

Or

FSomeDelegate& delegateRef;

 

This will not work and Visual Studio will have warned you even before building or as building errors. Specifically for the Pointer type, You may get the error: 

 

cannot have an exposed pointer to this type.

 

and for the reference method , you may get a build error saying something along the lines of: 

 

references must be initialized.

 

That is because in c++ a reference needs to be set at declaration.

The Workaround

A solution that often works is to get a pointer to the UObject* that contains the unreal engine delegate. The downside is you will need to go through this UObject* to access the delegate every time in code but it’s a small tradeoff. Here is an example of calling the Broadcast function through the UObject.

UObject->DelegateVariable.Broadcast()

5/5

Gamechanger plugin for notehighway rhythm games and music visualizers

5/5

Add Text and 2D UMG widgets to Level Sequences

5/5

Simplify your Plugin Development with the Unreal Projects Manager

5/5

Learn how to create unreal engine plugins from scratch and sell them on Fab.com.