While it is perfectly acceptable to handle updates within character blueprints, sometimes it doesn’t make as much sense to perform all updates immediately when in a multiplayer experience. I previously wrote about creating a game tick that could be used for timed updates, but I didn’t have a hook into how to perform those updates. I created that hook by using an event dispatcher within the world tick logic. This allowed me to add events to the dispatcher queue and execute the queue at whatever interval the world tick was running.

So the logic works something like this…

Event happens → Add reference to an event to the event dispatcher → OnWorldTick, process everything in the dispatcher queue → Empty queue and start over

That is still too conceptual for my liking. Let me give you a real example that I developed as a proof of concept.

  • Player runs out of food and begins starving
  • The HungerDamage event binds ApplyHungerDamage to the GameTickDispatcher defined in MyGame
  • The WorldGameTick reaches the end of its current tick cycle and triggers ProcessWorldGameTick
  • ProcessWorldGameTick calls the GameTickDispatcher to execute everything on the stack
  • The ApplyHungerDamage event is triggered and whatever logic in that event happens
  • The ProcessWorldGameTick unbinds all events from the dispatcher
  • rinse, repeat, profit

Now I don’t know that I would actually want the entire game world’s hunger to only decrement the player health on a world tick, but I did this with 3 other attributes on the character and they all execute as expected. I used this to test regeneration and decrementing health. The nice thing is that is appears the event dispatcher is intelligent enough to prevent duplicates. If your logic just pours the flow into the branch that adds things to the dispatcher, it will only add one event until the clear is queued, then it will add again. Very handy, and means I don’t have to add additional layers of branching.

You know I like pictures, so here is a couple of screenshots to show you the setup.

ProcessWorldGameTick

Here is the event dispatcher being called and cleared in the processing of the world game tick

Hunger Damage Logic

This is how you would add an event to the dispatcher from a different blueprint. The event only gets called when the dispatcher is called.

As for how to create the dispatcher… that is just a couple clicks on the left side of the blueprint window (same place you add a new variable, just hidden behind the double arrows usually). Creating the dispatcher will allow you to manipulate it as desired. For more information about event dispatchers, you can also read the official documentation here: Event Dispatchers

As always, let me know if you have any questions or would like more detailed information on anything I post.