How important it is to destroy a Timer

Hello everyone

I’m working on an adventure game with lots of RPG Elements, and one of these elements are spells, I use A LOT of Timers in those Spells and since I’m terrible with optimizing C++ code, I was wondering exactly how important it is to actually destroy those timers and what is the best approach to do so. Most of them are used for Damage Over Time spells or Regeneration Spells and their Handlers and Delegates are defined within the .cpp function that calls them, not on the header.

PS: They don’t seem to have any impact on performance whatsoever this far, even when casting 10, 20 spells, I’m just asking this so they don’t become an issue in the long run.

When the owning object is destroyed, GC takes care of the timers for you.

Ty for replying, but what about persistent objects? Example, if I have a spell that heals the actor overtime, but the whole local timer is created and handled on the actor doing the healing, so he can stack heals, in that case, do I need to destroy the timer once that stack of the healing ends? Sorry if this question is too dumb btw.

Unless you’re making something very specific, when owner actor is destroyed its Uobjects should be destroyed too. If you’re not sure, call BeginDestroy() on the Uobject within the overriden Actor’s destructor function.
You should not create a timer object everytime you want to use a skill, the timer object is destroyed with the owning actor so there’s no reason to delete and rebuild the timer object more than once.

Oh, I think I got it ! Thank you very much!