Download

How to Properly use Event Tick?

So, i read somewhere you should avoid using “event tick” whenever possible. Is there a better way to implement a HUD system then using “event tick” it in your characters blueprint?

The more things you do in Tick, the more likely you are to lower your fps (because you’ll be busy doing your Tick things, instead of busy running the game).

So with that in mind, it’s totally fine to have some things in Tick. As long as you keep it to “some”. A single player’s hud is fine, but doing something for hundreds of spawned actors is probably not.

That said, a hud doesn’t seem like something that needs to be updated every tick. It seems like something that should be updated whenever something it’s displaying is updated. Which means using events. Here’s a doc for it: https://docs.unrealengine.com/en-US/Engine/UMG/HowTo/EventBasedUI/index.html

The idea is to only run code when it is relevant. To use your HUD example, instead of using tick to check every frame to see what your health is and set that in the HUD, you can just start an event every time your health changes in either direction. Then you can listen for that event in the HUD and change the health displayed just one time.

The other benefit of this is once you setup your events, you can listen for them in multiple places. Maybe your game mode blueprint listens for the health changed event and checks to see if you died. Maybe your player character checks to see if your health is low enough to start a bleeding particle effect, etc. If you truly only have one other object that needs to receive the event, you could just call a function (health changed, call the function in the HUD that the health changed). It can be easier to start out with the event setup in case you discover more things that want to listen to that event in the future though. That way you don’t have to re-do your previous blueprints.

The documentation doesn’t list the “Event Begin Play” as a starting point instead of “Event Tick” Are you by chance familiar with this and is it just about as costly as “Event Tick”?

I saw someone using this in a tutorial.

Begin Play only happens once, when the actor is created/added to the level. So it’s fine to do more things there, since the worst that’ll happen is the framerate drops that one second you’re adding the actor to the level, instead of dozens of times every second afterward.

I truly appreciate the help.

You can usually get away with using a Timer set to 0.05 (20 Calls per second) on Loop to do most things I’ve see people use Tick for, such as Moving Actors enough to fool the human eye. Instead of thinking of it as ‘The Tick Node’, think of it as ‘this is gonna fire every frame no matter what’, then ask yourself whether you need that. It’s useful for quickly testing things, but there are more efficient methods. Good practice is to work towards Event based logic, rather than ‘constantly check state’ logic.

I understand that avoiding tick when you can is the best practices, so that being said is there a way to make a clock without using tick?

The post immediately above yours literally answers that.

Timers are more efficient than Tick and a lot easier to debug. Tick is only really necessary when dealing with rendering and even then it may not be required like with UI and Animation.