Question about TickComponent function

Every time we need to write some code into the TickComponent function, the same question pops up into my mind. Throughout the courses in Bulls Cow and Escape Room, it is being stressed that we should make our code as smart as possible to avoid impacting the performance of the game / computer. Having the system executing code on every single frame, isn’t that incredibly consuming?

For example the open door component, unless I completely misunderstood it, that code keeps running. Even though the door is visually completely open, the code is still pushing the door further open as it will never exactly hit its targetyaw. So on 60fps, the program executes 216,000 lines of code per hour to keep a single door open, do I get that correct? How does that not impact the performance of the game? It really struck me in this lecture, as we see the UE log bombing away output with our position and rotation when we walk through the game. Can someone give me some color on this why this is ok?

Thanks!

You’re absolutely right and there are a number of ways to get around this.

For example, instead of this you could probably use a timer that starts on the overlap event to open doors and when the door is open as far as you want, the timer is terminated. Similarly, on leaving the area where the overlap is, you’d need to reverse it. The flip-side of this is the code becomes more complex.

You can also be smart by adding a check in the TickComponent method to check to see if you need to execute the rest of the door code, a simple indicator that says if opening or closing, animate that gets set on overlap or leave on the trigger volume. On finishing opening or closing, you can set an open or close as well. This would mean a 1 line check per tick.

You have to bear in mind that all the code won’t get executed every tick as well. There may be 6 lines of code (assuming 60fps) but if there’s an IF opening, the code inside the if would execute otherwise skip and so may just be 1 line of code.

It’s not quite as clear cut as that but think about it another way. Binding actions/axis, timers and other events are also polling in the background as well as animations in the models on screen where you may be doing absolutely nothing to handle, they just work.

In a triple-A game, you’d probably have to worry about this but tick is generally ok for what is being done here.

A very interesting question.

1 Like

Thanks Beegeedee, that is really helpful. Most of the things you mentioned, currently I have no idea how to implement but that is alright for now, as for this game it isn’t a big deal. But it is good to realize that if I want to create something larger, this is an area to explore further and be mindful of. Thank you so much for your reply!

For the OpenDoor component specifically it shouldn’t really matter a whole lot. It’s performing a very simple calculation. I’ve tested it with 1,000 doors in the world and it’s not really noticeably affecting performance all that much.

If it is still a concern you could add additional logic to stop ticking once the target is reached.

1 Like

Privacy & Terms