Hello!
How to save a list of all instances of a class the proper way? I want my custom editor script to have a button that updates all other custom editor scripts of that type.
My first thought was to create a static List() and within OnEnable() to add the instance.
Two problems first occurred, there were multiple instances of the same class, and also after a script reload there were lots of null references. The static survives assembly reload but the actual values inside the list do not seem to persist.
@whydoidoit
How do would you guys solve this kind of task? (Update all instances of the class)
If it’s a custom inspector thing only, then you don’t have to worry about performance that much. You can just find all of the monobehaviour classes in the scene with GameObject.FindObjectsOfType there. Since custom inspectors are just sort of wrappers for real classes, you can do all the real work there, and if you want, you can just put all the editor related stuff between #if UNITY_EDITOR … #endif directives. Custom editor’s repaint every time you click or change something in the editor, there’s no use trying to keep references to them. In case you really need something passed on in the custom inspector script, you can use some static variables that are used in OnInspectorGUI, but i wouldn’t rely on this too much because it only gets called when you select the object.