Setting Default References for Static variables?

Hi there!

My enemy prefab contains a script which contains an array of Texture2D objects. I set the default references for the Texture2D variables in the editor, and everything works as I expect.

Then I figured I should make the textures and array static, as the textures will always be the same so there’s no sense for every enemy to have it’s own copies.

So I made the textures and array static. Then when I ran the code, all my textures were black. I had a look at the script in the editor and noticed all the variables I made static are no longer shown in the Default References window.

Can anyone tell me how I set Default References for static variables?

I hope someone will tell me I am wrong, but I don’t think it’s possible to set static variables on a GO using the Inspector.

You could look into using a single singleton-like GO to manage your textures, then have the all the enemies look at that Manager to find get their textures.

But IIRC when you instantiate a prefab, it does not recreate all the assets it is referencing. It just keeps a reference.
So, in fact, the overhead of having each enemy with it’s own list of textures is just the cost of the variable and the reference to the texture. Not a very high cost, so maybe better to leave it the way it was.

You can’t do this at the moment. It sure would be nice. I use the Manager solution mentioned for this kind of thing.

There is a request for this feature on Unity feedback: http://feedback.unity3d.com/forums/15792-unity/suggestions/389041-editor-static-variables-editable-in-inspector?ref=title

Thanks guys!

@pakfront Good point. Will revert back, as just having references shouldn’t be too bad.

As I mentioned on the feedback thread, this feature would be more than convenience:

I do this quite frequently, And in my opinion, when you use a singleton-esque manager object, you don’t really need to make the variables static, right? I mean, you only plan on ever having one instance of this object anyway.

So ultimately, what is the point of static vars? I can’t say I’ve ever encountered a practical application for them (in Unity).