Reputation: 41
I defined a superclass named LLM and set some of its variables to "[SerializeField]", because I wanted them to be modified in the Inspector window in the scripts of some subclasses. Now I want to create a subclass that inherits from the superclass, but I want some "[SerializeField]" variables in the superclass not to show up in the Inspector window. How can I deal with this problem?
I asked ChatGPT 3.5 to find some resolutions, then I tried this [HideInInspector] protected new string m_Prompt;
, but it came out with this error The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(LangChainSpark) m_Prompt
Upvotes: 2
Views: 114
Reputation: 116
Writing custom inspector will do what you want but it's really hard and need lot of work now and maintenance in future so I don't recommend it. other than that I think it's not possible.
As I know generally there is not a good design that you have an inherited class that change some of parent class behavior.
if you don't want some of these behavior in some of child classes so those are not children of your parent. to fix this maybe you can break down your parent class to smaller ones and assign them as separate components that can work together or even call each other. so with different combination in component you can have different object with different behavior. beside that you can define an Interface with different implementation that one of them has mentioned variables as SerializedField
and another one is not and assign each one based on your need.
Hope this will help you.
Upvotes: 1
Reputation: 3333
I think you might have to write a custom editor for the child class, and then you can control what is displayed.
https://docs.unity3d.com/Manual/editor-CustomEditors.html
Upvotes: 0