- Home /
Need help understanding scriptable objects.
I understand the concept of scriptable objects but I'm having a hard time understanding the implementation. I have a small example case. In this example I want to create a buff system with just two simple buffs. One that heals the user over time, and one that damages the user over time. Both stored on some Power Up gameobject which activates when the player touches it.
My initial thought is to have a list on the player that stores the buffs/debuffs so they can be removed and checked at any time.
I think the biggest problem is implementing different methods for different buffs. As I see it I just need a BuffBase scriptable object which contains an abstract method for activation and maybe a GameObject for the user who runs into the Power Up.
But if I need different methods for a lot of different types of buffs/debuffs and the only thing they share is who the user is and an activation method, which gets overwritten, is there a point in using scriptable objects?
As I understand I will still need a new monobehavior script for each of my buffs with their unique activation method.
I dont really understanf your question, is about using scriptableobjects or using parent/childs? If you think you are not going to save any time by using a base class there is no point in using them. Scriptablr objects cant be monobehaviour i think there is something you missunderstood.
The main question is about scriptable objects as a base. Since I want to store the buffs in a list on the player I need them to be the same type (at least that's what I understand). So if all my buffs derive from the same base and share an activation method from that base. Then I can run through the list on the player and check if eg. the player is periodically gaining health from a buff, or remove a specific buff from the player.
I understand how to create the buff base, but when I want to add what each buff actually do once applied, I hit the wall. Since I want several buffs which behaves differently, for example some are doing stuff periodically in the update, some increases a stat some decreases stats etc, the only way I can think of is having a new monobehavior for each buff. Which kinda seem to remove the concept of having a scriptable object to begin with. Unless multiple types of monobehaviors the way I describe it is completely normal.
Whats the porpuse of using the scrptable objects? You can add different functionality to each ability why is that a problem? You cant drive fron monobehavior and scriptabke objects
Answer by Hukha · Mar 31, 2019 at 12:48 AM
Hi,
First of all, sorry for my poor English.
You understand SO(ScriptableObjects) bad. SO only store "data". They aren't GameObjects.
I dont recommend it for "Buffs" so i give you an example with other Stuff like "Items".
Imagine you need have 2 types of items(Bows and Swords).
You need a BaseClass SO named "Item" with an enum variable (Or whatever) to identificate the type of this item, and childs of this class named "Bow" and "Sword" with the needed variables for this classes. (Like Damage for the Sword and ArrowStock for the Bows, for example)
Now, you need to create a Item in your project from the child classes and this child have the "Item" class variables and the variables of the child.
[CreateAssetMenu(fileName = "Sword", menuName = "Item/Sword")]
This two Tutorials are good enough to understand SO:
Why? No, scriptable objexts arent for storing data, thats just a functionality. They are classes, use because they receive events and are easy to serialize. Buffs is a good use case of scriptable objects
Your answer
Follow this Question
Related Questions
Unique function for each instance of a scriptable object 2 Answers
Unity : Singleton ScriptableObjects resets after play 1 Answer
Need some advice for my inventory system 0 Answers
How to Instantiate objects that are Scriptable Objects 0 Answers
Serializing ScriptableObject into scene without writing to asset 1 Answer