This may be more of a general programming question. I have spawned multiple actors of the same class on my level. I want them all to start doing something when I press a HUD button (e.g., call a “FireAttack” function). I can think of two ways to do this:
- Have the button set a boolean on my GameState variable, and have each actor check that variable on every tick to see when it’s time to attack.
- Have the button send an event to the GameState, the event then sets a variable (or calls an event) for each actor on the level (my Gamestate keeps references to all the actors).
Which option is better/cleaner? Are there better ways of doing this? Thanks in advance.
if all this actors do this in exactly same time then:
make event dispacher and bind function. It will execute once when called. It will be best idea.
Blueprints works better when they are event driven.
Thanks for the reply. So I would have to make a For Loop and go through the actors to fire the event, correct? Or is there a way to make the event fire in all spawned actors?
No you can bind event to each actor (Yes you can bind multiple events to one dispacher and all will be executed) If this is same actor type you can do it simply with bind event to … in begin play or so. This will don’t make you do it again for each actor as it will be done automatilicaly.
Thank you, worked beautifully. I thought events would be tied to a particular instance, but all instances respond to a bound event.