How to make a CPP event execute before the blueprint event is fired?
I have a health bar that is being updated in a blueprint and the main event is being computed in CPP. Whenever the health bar updates, it is always one update behind the CPP. For example, if I log the current health in the CPP function and the blueprint. Assuming the player has 100 health and get damage of 1 the CPP will print 99 but the blueprint will print 100.
It is like the blueprint gets called before the CPP when the event fires.
Blueprints are executed with same thread as C++ and vice versa so ordering of things depends when engine code or your calls of blueprint functions and events, there no magic here and CPU need to execute in specific order one by one in here and order need to be pre-decided. So what you see means Actor event is called first which calls BlueprintImplmentableEvent to blueprint and then delegates binded to them in order of stacked bindings. Sometimes with overriable function you can somewhat control of order by calling Super::*** in specific point, but if it’s internal engine delegate call (and considering you want to avoid decency of actor as you use component) this is most cases impossible without editing engine code
But since you making you own health component, actor should relay on that component not it’s internal damage functions anyway. So make a delegate in component under same type FTakeAnyDamageSignature:
Now in blueprint event should show up in properties when you select the component and you should have big green + button that will add the even in more compact way then you would typically do with delegate/event dispachers.
Since you making you own system you might be interested on passing to blueprint more information together with the event, in that case declare your own delegate type as described here:
For blueprint use (with BlueprintAssignable) you need to make dynamic delegate:
Thank you for your detailed advice. I will use your suggestions and let you know how I go. If it solves my problems I will mark as the answer. Coming from a pure CPP background I am still learning how to link the blueprints and the code together. Thanks, once again.
That’s what I was thinking originally but it didn’t seem to have that as an option, my other concern was that the engine would fire the event, then I would refire the same event from the blueprint creating an offset but the other way around. Thank you for taking the time to offer advice.