There are multiple reasons why a function that was bound using AddDynamic() may not get called or appear not to work in Unreal Engine C++. This Tutorial will cover some of those scenarios and how to solve them.
Common Developer Mistakes
- You are not getting Delegates by reference before you call AddDynamic On Them. You should almost always get a reference to the delegate, not a copy. Example of how NOT to do it:
FDelegateName theDelegate= getDelegateFunction();
This is wrong and you will get a copy instead of the delegate you want to bind to. Instead, use:
FDelegateName& theDelegate= getDelegateFunction();
Emphasis on the ampersand sign( get by reference).
The delegate is not getting Broadcast anywhere in the code. If Delegate->Broadcast is not getting called anywhere in the code, that means listeners(functions) will never get triggered. Sometimes this may be your error if its a custom delegate or a bug within the engine itself if its an engine delegate. The delegate may not have ever been called.
- Garbage Collection. Check if your delegate owners or broadcasters are not getting deleted on invalidated by the garbage collector. Ensure you have protected/or added them for reference counting by using UPROPERTY where appropriate.