I made a status effect system using scriptable objects, it has some main values like totalDuration
, remainingDuration
, … and a Coroutine
to automatically make itself expired after remainingDuration
runs out. I also have a effectHandler
class that stores a list of statusEffectSO
and automatically removes them when they’re expired (also for displaying UI).
So I put everything in place for testing and I realized they were referencing the same asset SO file. That means when ONE of the effect runs out, ALL other effects on different targets also run out.
Then I applied a band-aid solution so that every time I apply a new effect to the effectHandler
class, the handler will INSTANTIATE that effect to make an instance of the effect values so that it will run independently. Then when it is expired I will DESTROY it and remove from the list.
TLDR: To make my statusEffectSO
system works, I Instantiate a copy of the effectSO
then Destroy
that copy when the effect expire.
**The question is: **
How costly are those Instantiate
and Destroy
calls on Scriptable Object
? How fine is this? Or is there a better way to do this?