- Home /
[CreateAssetMenu] For inherited ScriptableObjects
I have a class Ability that inherits from ScriptableObject. I have dozens of classes that inherit from Ability to implement additional custom functionality.
How can I easily create the assets needed for these grandchildren? Putting [CreateAssetMenu] property on Ability doesn't work (presumably because the attribute is outside of the class?). Other than manually writing CreateAssetMenu into every single child, is there any other solution? Kinda defeats the point of OOP if I can't even get this behavior to propagate to child objects.
Answer by Bunny83 · Jun 21, 2019 at 11:35 PM
The CreateAssetMenu attribute creates one specific menu item to create an instance of that specific type. So yes, you have to attach it to every sub class and you probably want to specify a path / unique name for each class.
Attributes are not members and not part of any OOP structure. They are just meta data that is attached to "something". That something has to directly follow the attribute. So the attribute is not "outside" the class, it's attached to the class type itself.
Besides the menu item name you can also specify the default file name that should be used when creating an instance and you can also specify the menu item order. Of course this has to be specified for each concrete type you actually want to show up in the create asset menu.
Semantics aside, that's essentially what I thought/said in OP. I had hoped Unity might have come up with a better solution, as I can't be the only one using grandparent SO's at an extensive level. Ah well.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Navigate UI with gamepad 0 Answers
How to render images from JSON in Unity? 1 Answer
Enemy clone not following script 1 Answer