Branch or gate, event tick

HI

Beginner question.
What should I use when I need to use some logic every tick but only sometimes (some interaction like pushing an object for example and update some variables while doing this). I mean many tutorials use the branch node. And it seams that it checks some bool every tick. That is not good I guess. So I thought that I could use Gate node with event that will open it and another event that will close it. But if you can double click on Gate node and see that there is another bool inside that is checking every tick. Use timer with small interval also is not a good idea. So what is the way?

And also I want to know, when I have some custom event on my blueprint, if there are some branch deep inside on code that checking every tick if this event is happens? And makes it equal to every-tick-branch node?

In order to optimize your game, Tick methods should be as empty as possible. Bool check is pretty much cheap. I use it, and haven’t had any issues. It is much better to use event based actions, as much as possible instead of doing logic in Tick.

There is no any additional checks for custom event. It is, as it’s name says, event based. Called only when you manually call it. Like a function in the C++, or other programming languages.

2 Likes

anything following from event tick is getting called at the tick rate (every frame unless you adjusted it).

Just dont put any complex math or “Get all actors of class” on it and you probably won’t see a problem.

But if you can otherwise use a timer or find a way to get the same results by using custom events, that’s better.

Get code working first so you can play your game and make the actual important decisions. Only make micro-optimization decisions once the game is verified. Otherwise, you’ll never finish. In other words, if using tick gets you to the point to where you can play your game sooner, use it. Worry about clean up code and optimization later - because once you start actually playing your game, you will be rewriting things many times. So optimization prematurely just means you will get burnt out from doing extra work for nothing.

3 Likes

If you need to check a bool, you need to check a bool.
The CPU is there to be used, and using too much of it is only a problem if your frame rate doesn’t hit your desired target on your specified target hardware.

The bigger cost here is implementing “tick” in blueprint at all. Once you do that, checking a boolean isn’t particularly more expensive – you already paid the price of having a blueprint tick.

If you’re going to use hundreds or thousands of this actor, and it needs to sometimes do a thing, then what you should do is not use tick, but use an interval timer, and set the timer to call back on interval when the condition becomes true, and clear the timer when the condition becomes false again.

By the way: there already exists a system that will do this for you; it’s the gameplay ability system. If you can program in c++, and the actors that need to conditional behavior are some kind of game logic actors (characters, npcs, etc) then you could probably implement the conditional logic in the GAS, by adding an effect tag when you want it to start, and removing it when you want it to stop.

2 Likes