- Home /
Scriptable Object with Abstract Class field,Reference non-instanced inherited class through abstract field.
I built my inventory system based off scriptable objects with a base item class. The weapon scriptable object has a field that’s type of WeaponFunction, an abstract class with an abstract Attack() method in it.
I made a Sword class that inherits WeaponFunction and overrides the Attack() method. The Unity Editor won’t accept the Sword class as a valid entry in the scriptable object’s WeaponFunction field.
Is there a better way to do this? Is there an example of this kind of architecture somewhere I can take a look and see how someone else did it better? ,I built my inventory system around a bunch of different types of an item scriptable object. For the weapon item I defined an abstract class for that contains an abstract Attack() method and have a variable in the scriptable object that’s type of the abstract class.
When I write a new class, Sword, that inherits the WeaponFunctions abstract class unity won’t let me assign it to the WeaponFunctions class.
Is there a better way to do what I’m doing? How has this been done before? Is there a small fix I can do to get my system to work?
What you'll want to do is create an ID for the WeaponFunctions, and load them either dynamically or into a dictionary, and then have a ID reference in the item so that it acquires the proper reference. You see, Unity doesn't handle serialization of inheritance on members and fields, so to get around it, you need to assign it at runtime, or keep the reference elsewhere.
there is something wrong in the way you are oding it since, scriptable objects are just claasses and can be use as parent/child without problems, share your code and i will try to find the error
Your answer
