Edit Static Class Config variables from editor

Hi all,

i’m using a static class with static public variables for some development configs. For example there I put the terrain layer name or the Debug flag, variables that will be accessed for many GameObjects.

I wonder how could I do to make a Custom Editor for the inspector in a way that I could modify this varaibles directly from the inspector.

Also, my mind is open to listen other advices about where to store this kind of variables.

Thanks,
Metinu.

In short: you can’t. Static classes as well as static variables aren’t serialized. Therefore even when you create some editor GUI to edit those values, they won’t be saved.

There are several ways to accomplish this:

  • Using an actual instance of a class and store the values as instances variables. You usually only have one instance of that class so the singleton pattern might be used to access those values from anywhere. You usually would use a ScriptableObject derived class which will be stored in the resources folder.
  • If those values are only relevant for the editor (so they are not used at runtime) you can use EditorPrefs instead. Note that the EditorPrefs are not stored inside the project folder, so they won’t be transfered to another PC when you copy the project folder. Those are usually used for pure editor settings which have no relevance for the actual project.
  • Use your own serialization method. This could mean serializing the values as JSON or XML into a file which can be loaded at runtime / edit-time.

Which method is the best highly depends on the actual usage of those “values”. If those settings are required at runtime i highly recommend the ScriptableObject / Singleton approach.