I need to set some variables in one of my runtime scripts, but I need to do it from an Editor script that is targeting a different script.
DataScript + DataScript_Editor
needs to set variables in
Can I do this simply having the RuntimeScript vars as static? Would assignment of static properties persist through playing & stopping the game, quitting Unity, all the way to publishing builds, and they’ll never change or reset unless I explicitly reassign them? — Is this what static vars are for? — Or is there some conditions where a static var will be reset?
The actual use of static variables is a variable that extends across the entire run of the program. Whether you use a static variable or pass an object around has no effect on when the variable is removed from memory.
In your case using a static variable would be incorrect. When you stop running the program it will be removed from memory (as will any other type of variable).
I feel that the function DontDestroyOnLoad may be of use to you. As for going across builds, you can check out something like PlayerPrefs. You’re going to need to save the data externally (Example: Database/file).
Static is not meant to be a variable to live for the whole extend of a program, it just happens to do so but this is in no way why it was defined.
Static is a variable that belongs to the class while others are instance members. The reason why it lives through the whole project is because it belongs to the class and not to any instance objects. As a result whether there is an instance or not, the static is there since the class is just a mold for object and is always there.
Like the count of enemy is a candidate for static as you need to keep track of how many of them and if none left you still need that value for later when you create new ones.
Nonetheless, whatever you do with a static can probably be done without it.
Static is like any other variables, stored in the ram which is a volatile memory (values are just electronic impulse) so when you put your computer off all is lost. For this you need to store on the ROM via some text file or player prefs class from Unity.
Finally, static variable do not show in the inspector since they do not belong to the object but the class (I start to repeat myself). So the inspector do not show it.
Still it is possible to create a public instance variable that will set the static in the start or later. Other way is to use an Init(value) to set the static when needed.
Currently, for storing data between editor sessions you can use ScriptableObject. Notice that you can’t modify it in runtime inside a player, only in editor. But I think it fits to your requirements.