• 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
0
Question by pion · Aug 02, 2011 at 01:16 AM · inspector

Accessing values entered at Inspector using C#

I've the following c# code snippet:

 public enum ToolMode
 {
     ELLIPSE,
     LINE,
     RECTANGLE
 };

 public ToolMode toolMode;



The "Tool Mode" shows up at Inspector as expected. I then set it to RECTANGLE at Inspector. Somehow the toolMode == ELLIPSE at my script.I was expecting to be RECTANGLE.

I want to be able to use the value entered at Inspector.

What did I do wrong?

Thanks in advance for your help.

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Aug 02, 2011 at 01:28 AM

I don't see any problem with using enums and assigning values in the inspector. A lot Unity standard-assets-scripts also use enums like the mouselook (as far as i remember).

To sum up your setup:

You have a GameObject in your scene that has this script above attached. You have selected the object and set the toolMode to RECTANGLE. When you run the game toolMode should be set to ToolMode.RECTANGLE

Are you sure you don't reset the value somewhere else? Maybe in Start / Awake / OnEnable?

You can also check the setting when you run the game in the editor (during run mode). Is it reverted to ELLIPSE? If not it is set to RECTANGLE, maybe you query it the wrong way?

Comment
Add comment · Show 2 · 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 pion · Aug 02, 2011 at 01:42 AM 0
Share

I followed your advice above. I then figured out what I did wrong. I basically changed the Prefab value. I should have changed the instantiated value. Thanks for your help.

avatar image Bunny83 · Aug 02, 2011 at 02:01 AM 0
Share

You can also change the value in the prefab but if you changed it on the instance as well it gets overwritten. Overwritten values are bold in the inspector. You can either click "revert" to revert the changes you made to this instance and use the values of the prefab, or if the prefab should be like your current instance press "apply" to apply the changes to the prefab.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Change only PrefixLabel with Property drawer, use default drawing for rest of property. 2 Answers

Unity can't see any scripts 0 Answers

Game window keeps de attaching 0 Answers

Selecting base classes from inspector 0 Answers

Creating a custom inspector utilizing a list of class instances with serialization? 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