- Home /
Set default editor values for public variables in derived classes
Say I have these 2 classes:
public class Foo : MonoBehaviour
{
public bool Awesome = false;
}
public class Bar : Foo
{
public bool Awesome = true; // Wrong!
}
When I add Bar to a GameObject I want the default value for Awesome to be checked/true in the editor. When I add Foo, I want it to be unchecked. I want it to be the same variable though (base class and derived share same instance), so I know redeclaring it in Bar is not correct.
Normally, in a non-Unity project, I would set the value in the constructor, but I understand it isn't safe to use constructors for MonoBehaviour derived classes.
I don't want to use Start or Awake, because I don't want to set values when my game starts or scene loads, I just want to control the default values in the editor (design time, not run time).
Your answer
Follow this Question
Related Questions
An OS design issue: File types associated with their appropriate programs 1 Answer
Inheritance And Editor Targets 1 Answer
Initialising List array for use in a custom Editor 1 Answer
How can I improve the organization and storing of information for my FPS Character Controller? 0 Answers
Copy reference from one component to another derived component., 2 Answers