Variable states before play and after play

I had a simple question. Do the references to variables made in the editor phase be passed onto the ‘play’ phase when the game executes? I mean suppose i declare an array in the editor phase with editor scripts and populate it with dynamic data, will the array have the same length(same objects) after i start ‘playing’ the game.
my experiments show that the array is reset to zero length for some reason. am i doing something wrong? or does unity reinitialize the array once the play begins? is there a way to tell unity ‘not’ to reset certain reference variables once the ‘play’ starts?

Kinda hard reading that, and don’t quite understand what you mean. Are your scripts attached to objects. I know if you have a script for a name attached to an object, and set that public string variable to a name, and then play the game, it works fine on my end. Care to elaborate a little more? Then again I’ve only been using unity for 3 days. So I’m sure one of these pros can answer your question. :shock: :smile:

ok here is the simplified code

var eventList;

function f( ){
 Take inputs from  EditorGUI class.
 Populate the eventList
}

Now Run the game
Does eventList still hold the values it had?
Is there anyway of doin it in unity?

I have a public GUISkin mySkin object inside one of my scripts, I assign the value in the editor. When I run the game the value is held. Maybe it’s a java thing, but I know C# wise it’s holding the value.

No, I am asigning values from the Editor. The script is ‘executed’ in the editor phase itself. Can somebody point me as to how do I tell unity not to reload this script when the ‘play’ button is pressed?
I want unity to keep the state of the script the same as in the Editor Phase. I do not want eventList to be reinitialized during play.
Thanks!

If your talking about while game is running in editor you initiate your script then no. Unity doesn’t save any changes at all while game is in editor/running.

Right. Unity does not save changes when it runs the game. I am asking about vice versa. unity saves the state when you use the GUI editor to change attributes. These attributes are stored somewhere in memory and are initialized to that value.
in my case, I have a script that is initialized with dynamic objects from the editor scripts. I want to know if there is possible way to not reinitialize the variables of this script when the game begins ?

Sorry, probably far out of my league as a beginner to unity. Hopefully someone comes along and answers this :smile:

yeah hope so. by the way, i have been using unity for 8 months now. thanks anywayz!

If what you’re asking is if it’s possible to change the value of a variable you’ve set in the inspector during runtime through code, I don’t think you can. You’ll need to clear out the value you set in the inspector before you start the game, and after that your code should be able to change the variable.

I’m having the same problem as amith. I am attempting to set up a project for some students. I have built a scene manager that can execute in editor mode (before you press play and actually ‘run’ the game). The idea is to have an array that can have it’s length set and then the user can drag game objects that they have added to the project themselves onto this list.
I can get it all working, but when I press play the objects that were dragged on dissapear from the array and it’s empty again (although it does have the right lenght).

Got it working. My problem was I had my Awake function initialising the array. But it seems that the awake function doesn’t get called until the play button is pressed so it was initialising an empty array over the one I had populated in the editor. I just removed that and it worked perfectly.