Hey y'all! I've scoured the internet for an answer to this question, but I've had absolutely no luck. The question is, how do I hide a field in the inspector for the inheritor of a base class that does not hide that same field? The reason I need to do this is because the child class adds funtionality to automatically grab the elements and put them into the array field, but that only works for a more specialized application of the base class.
#Weird question about attributes and inheritance
1 messages · Page 1 of 1 (latest)
Adds inspector functionality?
I would make the base class use an abstract property and the subclasses serialize a field that is returned by the property
that way the base class is not serializing anything, and nothing needs to be hidden.
It's public. It's an array of UnityEvents. The way it works is that there is an "input" stored by the dialogbox object that maps to an event in the array of UnityEvents in the gameChunk object. Game chunks work kinda like passages in Twine. For simplicities sake, I made a class that inherits the GameChunk class called SimpleChunk. Instead of having a bunch of events that are plugged into the Simple chunks array, I want to hide that array and instead give the developer access to an array of Chunks. On enabling the SimpleChunk scriptable object, it automatically fills the array of Events by subscribing the method of the other chunks that it references. It creates new events and overwrites whatever the developer put in the array of UnityEvents in SimpleChunk which is why I don't want the developer to have access to those unity events. It's just confusing is all
The whole point of the simple chunk is to make it less confusing and streamline the process of string game chunks together without having to screw with setting up the UnityEvent in the inspector
Does that make sense?
I don't really think I need to understand whatever all that is tbh.
If you are trying to hide a serialized array you can use [HideInInspector]. Or make your own editor for the type (which honestly seems necessary to do whatever else you're talking about) and just don't draw that field.
If you don't want to hide something in the base class but want it hidden in the subclass then you either need a custom editor, or as I mentioned first the base class could just declare an abstract property which is overridden by the subclasses. If you had a BaseChunk that GameChunk and SimpleChunk inherited from then GameChunk can have a serialized array that is visible, SimpleChunk can not, and BaseChunk has the shared implementation.
I'm not trying to hide a serialized array. I'm trying to hide a public one. Is that at all relevant? Otherwise, I guess you're probably right lol. Don't know why I didn't think of making them siblings...
public serializes an array
public or [SerializedField] indicates to Unity that you want to serialize something (if it is serializable). public just also means it can be accessed elsewhere
None of what I've said goes against that idea
Doesn't work
Without a public field in the base class I can't manipulate all gamechunks the same way
What's the other option? Custom editor window?
I am not sure what you mean. Is it not set up something like this?
wow.... I didn't know you could use the override and abstract for fields. I feel dumb. I was using new, but I don't think that is correct at all
Gimme a sec
uhh...it won't let me use abstract on fields
It's a property, not a field
The base class declares an abstract property (in this case it just has a getter). This means that the inheriting classes have to implement that property. A property with a getter is just a method Get_Name that has nicer syntax making it look like a variable.
The subclasses declare fields that are serialized (saved), with one hiding it. They both return that field through the property by overriding the implementation. If anything wants to access the events they go through the property to get them.
neat!
Wait. I'm still getting a weird error and I'm not sure why.
It says "SimpleChunk.onInputFromDialogBox' cannot be assigned to -- it is read only"
Does this have anything to do with game chunks being scriptableObjects as opposed to monobehaviours?
Is onInputFromDialogBox the property?
yes