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
6
Question by Cobradabest · Dec 09, 2012 at 12:58 AM · c#inspector

C# Variables not showing up in inspector

I'm making my game using C# scripts, and the variables aren't appearing in the inspector, I could just go into the code to edit variables, but having them in the inspector would be far more convenient.

I've tried every solution I found online, I've tried making the variables public, didn't work, I corrected any errors in my code, still not appearing, I tried System.Serializable, nothing.

So what do I do now?

Here's the code I wrote to test it:

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]
 public class SomeMouseLookScript : MonoBehaviour {
     
     public enum rotationAxis {mouseX = 0, mouseY = 1}
     public int mouseXY;
     
     // Use this for initialization
     void Start () 
     {
         
     }
     
     // Update is called once per frame
     void Update () 
     {
     
     }
 }

I wrote this while following a tutorial, neither variables appeared in the inspector.

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 Lockstep · Dec 09, 2012 at 01:22 AM 0
Share

You have to post your script or else nobody will be able to help you.

avatar image T27M · Dec 09, 2012 at 01:38 AM 0
Share

The mouseXY is showing in the inspector to me, I'm not sure that the enum would show up.

avatar image sacredgeometry · Aug 20, 2019 at 08:49 PM 1
Share

Thats defining a enum not declaring a variable.

You would have to do

     public enum RotationAxisType {mouseX = 0, mouseY = 1}
     public RotationAxisType RotationalAxis;

For it to show up.

8 Replies

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

Answer by T27M · Dec 09, 2012 at 01:21 AM

The variables have to be public and part of the class, but not part of any method. Make sure the script is compiling as any changes won't show if the new script hasn't compiled.

 using UnityEngine;
 using System.Collections;
 
 public class MyScript : MonoBehaviour {
     
     public int number = 10;
     public string word = "Hello World";
 
     void MyMethod()
     {
         int anotherNumber = 10;
         
         string anotherWord = "Hello World";
         
     }
 }

So here the only ones that will show in the inspector and number and word. You could also try re-adding the script, but I don't think that will be your problem.

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
8

Answer by Lockstep · Dec 11, 2012 at 04:49 PM

I'm not sure if this actually is your problem, but is assume the int shows up but you also want to see the enum. If that is the case, well, an enum is not a variable. It rather defines a new type of variable. Like if you declare a variable as integer means, that this variable can have values like {..., -1 , 0 , 1 ,...}. Tu use the enum you have to declare a new variable as your enum:

 public enum rotationAxis {mouseX , mouseY }
 public rotationAxis someFancyName;

Then the someFancyName variable will show up in the inspector and you can choose it to be either mouseX or mouseY. To use the variable inside of your script you will have to use rotationAxis.mouseX to check for it. Like:

 if(someFancyName == rotationAxis.mouseX){
 
 //do something
 
 } else {
 
 //do something else
 
 }
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
4

Answer by Paulo Renaux · Nov 13, 2013 at 01:13 AM

If you just edited the script, saved/recompiled, try using Assets>Refresh (Ctrl+R)

Comment
Add comment · Show 1 · 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 $$anonymous$$ · May 13, 2014 at 03:00 PM 0
Share

i dont have enough rep to vote, but +1 for u

avatar image
2

Answer by ThirdhandGames · Aug 20, 2019 at 03:16 PM

If anyone is having trouble getting a variable of custom type to display in the editor, be sure that said custom type derives from MonoBehaviour. That was my problem.

Comment
Add comment · Show 1 · 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
1

Answer by jessmlilly · Jan 07, 2018 at 04:02 AM

It could also be a noobie issue. (It was for me). I did not notice I had a build error. Check your console.

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
  • 1
  • 2
  • ›

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

20 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

Related Questions

Values lost? 1 Answer

How to control serialized variables over the inspector pane? 1 Answer

Custom Inspector: Targets & GameObjects 1 Answer

Problem using EditorGUILayout.ObjectField with custom type 1 Answer

How to control the exposure of public variables in the inspector pane based on a value of another variable? 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