Help me get rid of my Event Tick Addiction!

(As always, I’ll start with the "sorry for my ■■■■■■ english classic).

Hey guys!

As a beginner on UE4, I’m always looking for youtube tutorials. And there is one thing that I hear a lot in those vids. “I hate when I have to use Event Tick” or “You should avoid using Event tick as much as you can”. So yesterday, I was looking into my project and I just realised onething… I’m a idiot! Yeah! I use so much this node, you guys have no idea. I had a policy of “It’s working? Then everything it’s fine!”

This is a print of ONE of my blueprints (It’s not even the main/player character one)

And that is from a guy that was planning to do a multiplayer with more then 50 players in the same level.

So, I was trying to clean all the mess, trying to change the ticks for some others events and right now I’m kinda stuck.
The most part of my tick events goes into branchs that check some variables and I have no idea of what to use instead them.

One exemple: I have a mount that has a simple stamina system. So when the player is mounted and press Shift, a Progress Bar shows up in the screen and the stamina start to decrease… When the player release the button, the stamina Increases and when it reaches 100%, the bar fade out and the screen is, once again, complete clean…
Right now I’m using the tick event to check if the stamina is equal to 100 (integer) and if the bar is already on the screen.

(The “UI ON” is set after the player press Left Shift)

Is there a way of using this same logic without the Event Tick? The most part of my event ticks goes into that kida stuff… Things that the player do not have any “direct participation”, like overlaping with something or pressing a key etc

Well, once again, sorry for any misspeling. My english is not something that i’m proud of but I hope it is understandable.

Hey!

I am a beginner myself but would like to give my opinion.

  • In your first example (with the stamina) I do not think what you are doing is necessarily bad. But maybe a little change in the organization would help you. I will try to explain with a mock-up blueprint

Instead of checking if the stamina is full every tick, it is useful to understand that the stamina can reach 100% only when you increment it. Therefore you make this check after you increase the stamina. And by putting a condition (to see if the stamina is full) at the beginning of your tick event, your tick event will make a single comparison when the stamina is already full.

  • Overlapping with something, is usually handled with Trigger Volumes and Overlap Events (ActorBeginOverlap, ActorEndOverlap, etc.) [Bluprint Quick Guide][2]
  • Pressing a key is also handled by input events. Preferably you would first create Actions or Axis using the Project Settings and then use the events on an Actor which has controls enabled.

Hey @LupenWonse! I really appreciate the answer. I’ll definitely try that!

One more thing. You said that what I’m doing is not necessarily bad. But I use this exemple a lot! With different variables being checked in different blueprints. What scares me a little, cause I want do make a BR game style, with more then 50 players connected in the same level. If I do finish the game, do you think that those Ticks, that are only checking variables, can be a problem?
I have no experience at all :'D

As far as checks inside the tick function, use them as sparingly as possible. As the gentleman above pointed out only perform checks when you need to check them.

In the stamina example, you have a variable that is constantly changing over the lifetime of the character. This leads to the idea that it’s best to perform routine checks on it as its being adjusted at regular intervals. And so is a good candidate for the tick function. You’re only other option would be setting a timer and calling an event or function at regular intervals. This has no advantage, as you’re just implementing your own tick method using a timer, so you’re complicating your code unnecessarily. A simple check is very low cost in the long run.

A good candidate for something outside the tick function might be a check to see of your character should die. This only happens whenever damage is applied and not at regular intervals. When damage is applied, perform the check, and respond accordingly. This is a good situation for ‘event’ checks that only occur when a specific ‘event’ has happened.

Basically if you have a variable that is updating at regular intervals then that is the reason for the tick function and it is generally best to handle it there. If you have checks that only need to be done when a certain kind of ‘event’ happens then perform your check during the ‘event’ and not during the tick event.

Well I have zero experience with developing multi-player, but since most of the things you are dealing with are local (i.e. UI) this should make no difference.

The game engine itself is one giant loop, and every Tick a lot of such operations are performed. I am not saying that trying to do everything in Tick is a good idea but it is better to avoid pre-optimization, especially when you have little experience. That means do not overthink a problem which you do not have yet. :slight_smile:

Btw. if you have not read already take a look at this free e-book Game Programming Patterns. It is a very interesting read and may help clear some questions.

Good luck