#It is and each field has SerializeField
1 messages ยท Page 1 of 1 (latest)
Item is a ScriptableObject, the ItemComponents are not.
You cannot serialize derived class type with Unity unless you use editor script, that's the thing
So I'd need to make the ItemComponents themselves also ScriptableObjects?
that would work, but it sounds pretty gnarly to me
That, or just make Item as prefab and add components on it ๐
That simply isn't how the system is built for game interaction, it isn't an option.
I'd rather not overhaul it as such.
However I agree on the topic of it being gnarly to extend from SO.
you can have the object be a prefab and never instantiate it and it would work pretty similarly
That doesn't sound too far away from just extending SO then
In terms of gnarly, I mean
That's also why we don't use SO. Impossible to refactor anything ๐
yeah, you're using a gameobject as a SO. the difference between it and the SO approach is that you can write your ItemComponents as normal MonoBehavior scripts and just attach them directly to the prefab
rather than needing to create a separate asset file for them
and you're going to need to write those classes somewhere, so just making them extend MonoBehavior isn't really a big deal
you can also use a custom inspector for your original design to work
That was my original solution, but I don't seem to understand it well enough for it to work.
did you use this: https://docs.unity3d.com/ScriptReference/CustomEditor-ctor.html ?
with true as the 2nd argument?
Un moment
I've been using PropertyDrawers, not a CustomEditor
I have two currently, one for Equip and one for Weapon components.
Do I need to make one that handles the base class and have it try handling the rest of the types?
honestly, its been a long time since I've done custom editor work. I don't know the answer off the top of my head
I'm looking at the docs to try to get a sense
Most importantly you need [SerializedReference]
I'm unfamiliar; hows that work?
Well it's recent Unity feature that support polymorphism
Under the hood it'd saves full type name as string
oh, it looks like CustomPropertyDrawer has the same flag for use for children. https://docs.unity3d.com/ScriptReference/CustomPropertyDrawer-ctor.html
You still need custom editor script
I'm sure there is some generic open source thing for this
I'd recommend just change it to prefab based and be less messy
Really you shouldn't afraid to refactor your things
So create a base CustomPropertyDrawer with that bool ticked for ItemComponent then?
yeah, I think that might work
Would that solve the others also not showing up?
Or would I still need a custom one for the rest?
Fair enough, thanks!