- Home /
Scriptable object sub-classes list
Hello, I want to implement quest system. The idea is: each quest data is scriptable object. This scriptable object contains list of tasks with different number of parameters. For example:
Create {amount} {Item_ID}
Upgrade {amount} any {item_rank} items to {level}
As you see, I have different number of different parameters for each task, and they all might be in one quest.
As I learnt before, I cant store all tasks in base class list, because it saves only base class data
Is there any advices or best practices to implement such a system? Or is there another way to do this for easy and convenient editing each quest later?
Answer by Bunny83 · Aug 14, 2021 at 10:25 PM
Nowadays you essentially have two options:
Use ScriptableObjects for all of your data classes since they support inheritance out of the box. You may add a little bit of editor scripting to pack those sub objects into the same asset file if you want to make it more clean.
Unity now supports the SerializedReference attribute. With that Unity actually supports inheritance for normal serializable classes. However you don't get much editor and inspector support for those. So while the SerializedReference attribute closes the gap we had for a long time, it usually requires a lot of editor scripting to utilize properly.
The fastest and most flexible solution is just using ScriptableObjects for all of your classes that require polymorphism. While storing each instance as seperate asset could get messy, using folders and sub folders usually brings some order into all of that. Seperate assets have the advantage that they can be wired up however you like in the inspector. If's also possible to use a little bit of editor scripting to store the sub object instances in the same asset file (using AssetDatabase.AddObjectToAsset).
Of course if you need more complex constructs you can always add more editor tools yourself like a seperate quest editor window with whatever functionality you need. Though it depends on your needs. Just as an example, here's my UVViewer which allows you to view and analyse the UV map(s) of a mesh inside Unity.
Your answer
Follow this Question
Related Questions
Error from declaring List within ScriptableObject 1 Answer
List keeps emptying itself 0 Answers
A node in a childnode? 1 Answer
Scriptable Object in Editor vs in Build 0 Answers