- Home /
Hide headers and variables in inspector from parent classes
Hi!
I have a class "Weapon" and a subclass "ThrowableWeapon". I want to hide in the inspector of the second one some variables and headers that were inherited from the parent. Is it possible?
I also would like to modify the default values of some public variables from the parent and show the new values as default in the inspector of the child, but I can't see how to do that. If I change the value inside the Start method of the child, the default value in the inspector is still the parent's default value.
Thanks.
Answer by Hellium · Sep 29, 2017 at 09:12 AM
If you want to hide the parent's serialized fields, you will have to create a Custom inspector and retrieve the fields of your derived class.
If you want to "override" the default value in the derived class, the only way I could think about is to implement the MonoBehaviour's Reset function and set the desired values here.
Reset is called when the user hits the Reset button in the Inspector's context menu or when adding the component the first time. This function is only called in editor mode. Reset is most commonly used to give good default values in the inspector.
void Reset()
{
parentAttribute = newValue ;
}
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
HideInInspector with inherited variables 1 Answer
Custom ordering of variables in inspector when using base and derived classes 1 Answer
Make a field in inspector hold inheriting classes 2 Answers
Parent Class variables in Child Class's Inspector (C#) 0 Answers