Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by sirconnorstack · Jan 19, 2014 at 10:38 PM · c#variableinspectorinheritance

How do I show a variable in my base class in the inspector?

I have two classes, BaseClass -> DerivedClass;

public class BaseClass : MonoBehaviour { public Enum baseVariable; }

public class DerivedClass : BaseClass { public Enum derivedVariable; }

derivedVariable is visible in the inspector, but baseVariable is not. How do I make it visible?

Edit: It actually works fine with ints. I was just trying to simplify my code for the question. In my actual code, I use Enums, and I'm guessing it can't display the Enums because they are declared in the derived class.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image joedartjr · Jan 19, 2014 at 11:26 PM 0
Share

Try changing the "P" in public to be lower-case at the beginning of the line BaseClass.

avatar image sirconnorstack · Jan 19, 2014 at 11:28 PM 0
Share

Oh, that was just a typo. This is just example code. In practice, should it work?

avatar image joedartjr · Jan 20, 2014 at 12:11 AM 0
Share

I'm not sure this will fit what you're trying to do, but it should access the baseVariable from the BaseClass script, and return it as a public variable in your DerivedClass script. I'm sorry if this doesn't help, I'm kind of out of my element with the class system.

 public class BaseClass : $$anonymous$$onoBehaviour
  {
        public int baseVariable;
  }
  
  public class DerivedClass : BaseClass
  {
        public int derivedVariable;
        public new int returnedVariable;
        {
             get { return base.baseVariable; }
             set { base.baseVariable = value; }
        }
  }

3 Replies

· Add your reply
  • Sort: 
avatar image
5
Best Answer

Answer by Benoit Dufresne · Jan 20, 2014 at 12:25 AM

Your code works, just with an error: MonoBehaviour, not MonoBehavior.

Variables don't show up correctly in editor until the code compiles without any errors. Eliminate errors and all public variables will show up, no matter how many levels of inheritance.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benoit Dufresne · Jan 20, 2014 at 12:32 AM 0
Share

Thanks, please accept that answer! Working on that karma y'know

avatar image sirconnorstack · Jan 20, 2014 at 01:33 AM 0
Share

Sorry, that was a typo, too. It's compiling without errors, but the variable still does not show up

avatar image sirconnorstack · Jan 20, 2014 at 01:45 AM 0
Share

Ah okay, so the code actually does work. The reason it wasn't working for me was that I was using Enums that were declared in derived class.

avatar image
0

Answer by sirconnorstack · Jan 20, 2014 at 01:54 AM

It looks like Unity can't display a generic Enum variable. It has to know the type of the enum.

For example, if I have an enum State

public enum State { Idle, Walking, Jumping }

Then this will be displayed in the inspector:

public State currentState;

But this won't:

public Enum currentState;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by lilsac · Nov 11, 2016 at 08:34 AM

Put [system.serializable] above the derived class definition

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

HideInInspector with inherited variables 1 Answer

Parent Class variables in Child Class's Inspector (C#) 0 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer

Unity Editor - Class variable value contrain 4 Answers

Execute method from unknown script set as variable in inspector 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges