I have a game where the player is operating a vehicle. Whenever the vehicle is moving, it’s ‘energy’ slowly goes down. When the vehicle stops, the ‘energy’ begins to recharge. I am currently doing this with Event Ticks. On it’s own, I assume this is a good way to do this. However, the vehicle also has different ‘systems’ such as ‘sensors’, ‘weapons’, etc. that all drain the energy as well. So, if the vehicle is moving, has sensors on, and is using it’s weapons, the energy will drop at the most rapid pace.
My issue is that when I have all these systems effecting the energy using Event Ticks, my framerate is dropping significantly. Is there a more efficient or better way to achieve this same functionality? Any help would be greatly appreciated. Thank you!
For simple math to affect framerate, you’d need to do millions if not billions of calculations per frame. My bet is that something else is causing the slowdown. (that’s unless you’re running it all on a dual-core 10 year old lappy). In 9/10 cases you’ll be GPU bound.
Perhaps the logic is flawed somewhere, you might be doing a lot of unnecessary casting, for example; or a sneaky double loop runs a million times too many. Consider accumulating all the energy drain in a single variable and then deduct it once per frame rather than having every subsystem tick separately. You could dedicate a single energy manager actor to this task.
Besides that, every actor can have its tick rate adjusted (Class Settings → ActorTick → Tick Interval).
Alternatively use a Timer instead of Tick, you can then have it precisely execute an EnergyDrain event every X milliseconds.
Thanks for the info, this should help a lot.
I use timers with combined with “retriggerable delays” and this makes me happy