Can't bind an event to a delegate during Blueprint Construction script

I want to use Components at what they are best at, composition, and use them to add custom events to my blueprints as soon as they have them.
For that I use delegates that I expose to blueprints.

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FEditorTickSignature, float, DeltaTime);

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class PROJECT_API UEditorTickComponent : public UActorComponent
{
    ...
    UPROPERTY(BlueprintAssignable) FEditorTickSignature OnEditorTick;
}

That seems to work perfectly, except for a special case, when I want to bind my delegate immediately after construction, in the construction script.
Construction script seems to be assimilated to a function, that means that the only node related to my custom event that I can drag for this is “Call Custom Event”, and there is no delegate pin on it.

222042-nopin.png

I don’t see any reason why this would not be possible, so unless there is something I miss, I see that as a missing feature.

Is this a feature planned in the future ? Does anyone know a workaround ?

Hello Grouflon,

Unfortunately, it is intended that you are not able to do this. You’ll need to bind your delegates on BeginPlay for the closest results.

Hey Matthew, thanks for the answer !
For the my case, BeginPlay won’t do, I want those delegates to be called in editor mode.
It would be possible in C++ though, so I’m not sure I understand the precise reason for this limitation, can you ellaborate ?

The main thing to keep in mind is that the Constructor of a C++ class and the Construction Script are two entirely different functions and run at different times. The reason that you cannot bind the delegate in the Blueprint Construction Script is because it’s run at editor-time and could cause some odd behavior from the actor at editor-time, since you’re changing the bindings. I’m not sure of exact examples, but the response that this is intended to not be possible comes straight from our Blueprints team.

Binding in the Constructor in C++ is acceptable but still can cause issues in some cases, such as this, depending on what kind of function you’re trying to bind.

Ok I understand. However, stated that way, it sounds like this problem is specific to some delegates and not to the whole delegates binding concept. In my case for instance, the API make It pretty clear that binding the delegate before registering the actor is safe in any case.

I’m not fond of the approach of forbidding an usage because some of its occurrences are dangerous. From what my 2 cents are worth and from the partial view that I have, I think the problem would be better handled through documentation and by adding understandability to the consequences of what you do than by just making the feature unavailable, but I guess it becomes an API philosophy & design question then :slight_smile:

1 Like