Blueprint Delegate is only working when bound after BeginPlay

Hi!

I have created a BP variable type that holds an object reference to a custom Data Asset class. These Data Assets are used as proxies for global variable data that is shared between various systems, and has has an ‘On Changed’ event:


// above class

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FHeraPropertyIntChanged, int32, newValue, int32, formerValue);`

 

// inside class

UPROPERTY(BlueprintAssignable, Category = "Hera|Property", Meta = (HeraProperty))

FHeraPropertyIntChanged HeraPropertyChanged;

Ideally we would like to bind to this event in the details panel as follows:

337359-bind-event.png

but the resultant event never triggers. However, if we bind ANOTHER event to it - after BeginPlay - then this second event DOES trigger. Here is a simple example:

When we broadcast the delegate, for the first bound function we end up in this section of code inside AActor::ProcessEvent and fail the ‘if’ statement (whereas the working event succeeds this check):

I found someone with what I believe to be the same/similar issue here, and while it has an answer I don’t know how I might go about fixing the issue: Blueprint Delegates and Event Calls - Blueprint - Epic Developer Community Forums

We would love to resolve this as it would avoid a huge amount of tedious & error-prone boilerplate code for our designers. Any help welcome, I’m quite new to UE4. Thanks!

EDIT: I’ve found that this works perfectly when playing in the standalone game, but doesn’t work in the editor. My understanding is that the original event is trying to call a function on an object whose world is invalid, whereas the events bound AFTER beginplay is calling a function on an object whose world IS valid…

This can often happen if the BP to be bound to isn’t ready.

You have at least 3 options:

  1. Put a delay in. Meh, not very professional, but a .2 sec delay is probably massively over the top, even from slow systems.

  2. Don’t bind on begin play. Wait until you can see the other BP exists and then make the bind.

  3. Put the actor with the bind in another tick group:

Hi ClockworkOcean, thank you for your answer! However, this isn’t the problem I’m experiencing - the event bound in beginplay works just fine. It’s the ‘Hera Property Changed’ one that never triggers

For future readers: it was recommended by Epic that data assets only be used for static/read-only data & references, and should NOT attempt to use delegates with them. We ended up (begrudglingly) making a component that bind the delegates instead. This wasn’t as clean of a solution, but it does actually work.