- Home /
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.
You have to post your script or else nobody will be able to help you.
The mouseXY is showing in the inspector to me, I'm not sure that the enum would show up.
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.
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.
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
}
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)
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.
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.