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
Psyche
Welcome to your next great souls-like adventure!
Status | In development |
Author | Sad Ogre Studios |
Genre | Role Playing, Adventure |
Tags | Atmospheric, Fantasy, Indie, mind-bending, psyche, Sci-fi, Singleplayer, Souls-like, Third Person |
More posts
- Problem: Harder Isn't Always More FunDec 14, 2023
- How to make the controller feel more responsiveDec 14, 2023
- ModelMayhem: A Programmer's TaleDec 08, 2023
- Problem: Face Your FearsDec 03, 2023
- Time to show our real main characterDec 01, 2023
- Problems: melee combat system is too boringNov 24, 2023
- Problem: Frames Win Games?Nov 17, 2023
- Problem with camera transitionNov 16, 2023
- Combo Attack systemNov 11, 2023
- Problems with code reusabilityNov 03, 2023
Leave a comment
Log in with itch.io to leave a comment.