Hello,
This is a problem I have encountered in several projects now, and I still don’t feel I have a good way to tackle it.
As an example;
I have an enemy which, when spawned generates a “threat” value. This increments over time until the enemy is destroyed.
When the enemy is spawned, GameState binds to the OnThreatChanged event dispatcher for that specific enemy. Then, as the threat value is incremented, GameState receives the notifications, and updates the running total of “threat” in the game. (there can be multiple enemies etc).
The process works - BUT - the code which increments the threat and calls the event dispatcher is capable of executing before the binding code in the GameState blueprint has completed. The result is that the first call to the event dispatcher is effectively unresolved/missed.
In this very specific case, the enemies have a “threat on spawn” value, lets say thats 5. When they spawn, a value of 5 is set on the enemy as its current threat, after that, its incrementing by a threat-per-second value. In testing, the initial value of 5 never makes it to the GameState.
If I pop a Delay node in to the enemy blueprint, with a value of 0.2, this seems to buy just enough time for the binding to complete - but I find this incredibly icky. Its such an arbitary guess at a number and could be influenced by other things, which would still result in the same failure. The obvious resolution would be to have the binding code report that it is complete, before any further actions are taken on the enemy. But in order to do that, the enemy would then need to bind to an event on GameState, which I don’t really like, as I’m trying to reduce how many “things” know about other “things”, so that they can all just do their jobs independently.
Has anyone else run into a similar issue, and if so, how did you go about resolving it?