- Home /
How can I make variables reset when leaving play mode?
I have this one very simple small script that's specifically meant for people to use while testing my game, now maybe I'm setting this variable up incorrectly but all I'm doing is this:
public string[] itemsToAdd;
And then while the player is in Play mode they add the names of any inventory items they'd like to add to their inventory and then press "C" to run a short function as shown here:
while(itemCount < itemsToAdd.Length){
if(itemsToAdd[itemCount] != ""){ itemToChange = CoreScript.GlobalVariables.Get(itemsToAdd[itemCount]); itemToChange.Status = InventoryItemStatus.Own; } itemCount++; }
Now this script works just fine, it adds all the items exactly as desired. The unexpected thing is that it does not reset back to 0 when leaving play mode like every other script I have does. It retains everything the player changed.
Answer by ScroodgeM · Aug 12, 2012 at 10:10 PM
methinks values are not reseted in prefab properties. prefabs can be changed at runtime woth saving these changes. instances in scene - no. so just instantiate prefab and work with it.
Answer by poncho · Aug 15, 2012 at 04:06 PM
use an "Initialize" method put all the values that your variables should have as you "reset" them then when you cameback to the play mode, activate you initialize method you can name that method "Reset" if you want
Answer by ruben_hiet · Jan 11, 2013 at 10:37 AM
Do you have [ExecuteInEditMode] on top of your script class because if you do that it will save every change of variable values when you stop your play mode to editor mode.
hope it helps,