• 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
0

Answer by ketura · Oct 03, 2013 at 10:34 PM

I know this question's old, but another answer that I found solved my run-in with this problem:

If you've refactored or renamed your script after adding it as a component to an object, it will stay as a supposedly valid script and will compile etc, but will only show the variables in the Inspector if your script's name and the class name are the same (so no ExampleScriptHere and Example_Script_Here nonsense).

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 AzzaMan · Jan 17, 2018 at 09:50 PM

I had the same issue. It has happened a few times and it is usually just a case of removing the script from the gameobject and re-adding it (I guess it is a unity compiling bug?).

However, a few times it has happened where simply removing then re-adding the script to a gameobject does not fix it. For these times, I had to delete the script itself, then remove the script from the gameobjects, then re-make the script and re-add it to the gameobjects. (IF YOU EVER HAVE TO DO THIS PLEASE MAKE SURE YOU HAVE A BACKUP OF THE CODE WITHIN THE SCRIPT BEFORE YOU DELETE IT).

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 StarArcher · Jun 09, 2020 at 08:52 PM

@Cobradabest : not directly applied to your example, but maybe this will help someone else who, like me, is a noob trying to figure this out.

Static objects don't appear in the inspector.
public static GameObject canYouSee; // does NOT appear in Inspector public GameObject canYouSee; // DOES appear in Inspector

FYI: Maybe don't use statics anyway. Try this: https://forum.unity.com/threads/singleton-vs-static.197169/

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.

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

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

Problem using EditorGUILayout.ObjectField with custom type 1 Answer

Custom Inspector: Targets & GameObjects 1 Answer

Best Practices: How to handle inspector's lack of interface support? 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