Is it possible to show Static Variables in the Inspector?

I am cleaning up the script in my game by moving all of the variables into one organized script. To make them available to all scripts I set the as "static var". It's been working/looking great so far.

Now I have a little problem. I use

var newObject : Transform;

for instantiating objects. I want to put all of these instantiatable object variables in my Variables script. However, when I set them as

static var newObject : Transform;

they vanish from the inspector. I need them to be in the inspector to set certain prefabs to these transform variables.

Is there some way I can make these viewable in the inspector? Or could I set prefabs within the script itself?

Thanks!

Use a singleton instead of making the variables static.

Yes, use 2 variables, a one called staticvar and one called setstaticvar, and in function awake, make static var equals the figure you set in inspector. if necessary place the code in plugins or editor folder if you need it to compile early.

#pragma strict

var setmaxsteps = 50;
static public var maxsteps = 50;

var sete = 20;
static public var e = 20;

var setinverfaces = true;
static public var inverfaces = true;


function Awake(){
maxsteps = setmaxsteps;
inverfaces = setinverfaces;
inverfaces = setinverfaces;

}

i thought that singletons were way unintuitive to learn, the descriptions i found here and on net seemed to refer to making a new class and functions rather than static vars.

It IS possible to see static variables in the inspector:

In the upper right hand corner of the inspector window there’s a little lock button, next to that is an icon of a tiny arrow pointing down next to three lines.

Select the icon of the arrow & three lines, you’ll get a drop-down menu. Select “Debug” instead of Normal and you’ll be able to see static variables.

It can be very useful for seeing what’s going on inside your scripts.

or you can use another variable to show its contents and if you modify it then the static variable also changes

public int myinspectorvar =0; // you can initialize it with wathever value you want
public int mystaticVar;
public void Update(){
    mystaticVar = myinspectorvar;

}

the only problem is when the static variable is changed from another script

As GeoMorillo said:

or you can use another variable to
show its contents and if you modify it
then the static variable also changes

and then he said:

the only problem is when the static
variable is changed from another
script

To overcome that problem you just make a function like this:

function AdjustStatic( amount : int ){
 myInspectorVar += amount;
 // add both negative and positive such as 5 or -5
 // Use gameObject.transform.SendMessage("AdjustStatic", 5) to adjust the...
 // variable from another object. Only adjust the static value from inside the object.
}

This is assuming you are updating the value :

function Update(){
   mystaticVar = myInspectorVar ;
}

You can also do something akin to this; it has worked for me:

[CustomEditor(typeof(OtherObject))]
public class OtherObjectEditor : Editor {
    public override void OnInspectorGUI() {
        StaticClass.staticEnumObject= (ENUM_TYPE)EditorGUILayout.EnumPopup("text next to enum field", staticClass.staticEnumObject);
    }
}

public static class StaticClass{
    public static ENUM_TYPE staticEnumObject = ENUM_TYPE.DEFAULT_ITEM;
        
    public enum ENUM_TYPE {
        DEFAULT_ITEM,
        ...
    }
}

public class OtherObject: MonoBehaviour{
...
// if you want it to reset on application stop
void OnApplicationQuit() {
        StaticClass.staticEnumObject = StaticClass.ENUM_TYPE.DEFAULT_ITEM; 
}

// Alternatively you can make an inspector button to do this for you outside of the application running.
}

here, take this easy solution:

public static int number;
public int _number;

private void Awake()
{
    number = _number;
}

you can change the static variable now in the inspector by having another variable which refers to the static one.
in my case its in the awake method, because i want to set it before the start method, so other scripts can get the correct number in the their own start method

cheers

This question was already asked and answered:

How does one inspect static vars?

For your specific case, however, I'd agree with Eric: Using a Singleton is the preferred method over using static vars to achieve what you're trying to achieve.

https://forum.unity3d.com/threads/how-to-show-a-static-list-in-unity-inspector.469253/

This worked for me:

public class Hello{
    public static int sOne;
    public int One;  //this variable will be shown in inspector
     
    void Update()
    {
    sOne = One;
    }
}

public class Hi{
// get static variable from Hello class
 private int One = Hello.sOne;

}