Problem with ability cooldowns


Reported by: Eldar Bertsel

October 13, 2023

THE PROBLEM

This week I ran into a problem while implementing the ability cooldowns. My abilities are made using scriptable objects and how I later learned you don't want to update the scriptable object at run time because once you exit the game the scriptable object fields will be overridden with the information that was loaded during run time. But I need a timer field to be in each scriptable object because I want the abilities to cooldown independently, regardless of the current class. So, I have 2 fields in there: cooldown and cooldownTimer. First is just a cooldown time that the ability will have and second one is a timer that will go down to 0 and when it reaches 0 the ability will be reset. The problem is whenever I play, use abilities, and leave the game when any of the abilities would be on cooldown. When I would run the game again, the abilities would have the same cooldownTimer as when I left, which is not what I want. 

THE SOLUTION
The solution to the problem was simple but it took a while to get to that solution. I had to create a list of the instantiated classes at the Start that would have a cooldownTimer = 0 for each of the abilities. This way, every time the game starts It will copy the list of my classes that I have, then instantiate new instances of those scriptable objects and set the cooldownTimer to 0. Technically even now when I leave the game with abilities on cooldown, the scriptable objects are getting overridden. But because I have that function in the start, it sets all of those cooldownTimers back to 0 at the beginning so no-one will ever know anything.

Get Psyche

Leave a comment

Log in with itch.io to leave a comment.