# Why don't variables in a script on a prefab clone store runtime changes?

I have a building prefab. There is a simple script attached to it that allows me to store unique data for each prefab instance, such as address. There are hundreds of clones of this prefab.

The prefab is instantiated like so:

//instantiate a "building" object :
multiFamHigh = Instantiate(multifamilyHigh,myV3,Quaternion.identity) as GameObject;

//set a reference to the prefab's behavior script:
BuildingBehavior bldgBhave = multiFamHigh.GetComponent<BuildingBehavior>();

//set the information for the prefab:


In the "TownCreator" script, after the prefab is instantiated, I call the setInfo function and pass the address to it. The setInfo looks like this:

public class BuildingBehavior : MonoBehaviour {

public void setInfo(string useString, int bldgListRef)
{
buildingListRef = bldgListRef;
}
}


The debug log correctly displays "you set address 3071 N." - meaning at that time, the "address" variable of the prefab script is set to 3071 N. Perfect.

However; later, when I click on any of the prefabs at runtime (via the mousedown) the UI message box pops up (as intended), and the Text is changed from "New Text" (default) to a blank string. I added a similar Debug.Log, at that point, and it also tells me that "address" on the clone is blank.

That code is:

 void OnMouseDown()
{
thisCG = GameObject.Find("MainCanvas").GetComponent<CanvasGroup>();
thisCG.alpha = 1;
CanvasStuff thisCS = GameObject.Find("MainCanvas").GetComponent<CanvasStuff>();
Debug.Log ("clicked on " + address);
}


This happens:

Any ideas why the script on the prefab clones is not storing the values?

Also - when I change (address) to ("Address"), the popup has "Address" above the OK, Thanks! button. :/

• We need more information, I fear. Show the code that you use to instantiate and call setAddress(). However, I suspect the reason things aren't working is because prefabs explicitly don't store runtime changes after the run has terminated. – Draco18s no longer trusts SE Jun 21 '17 at 21:05
• Thanks for the edit and reply. I can post more later - but I am not hoping for the prefab to store information from run to run, rather within a single "play" :( – scottwinch Jun 21 '17 at 21:07
• I was unsure. Even so, I need to see that section of code to determine what you may be doing wrong. – Draco18s no longer trusts SE Jun 21 '17 at 21:09
• Personally I'd want to see more context around your code because I'm pretty sure you are making a mistake like these are actually two different values which are both called "address". – jhocking Jun 21 '17 at 21:10
• @jhocking - I totally understand where you are coming from and will edit my post later tonight. The setAddress() and mouseDown() functions both reside in the same script on the prefab and both use the same "address" variable. I will also add the instantiation and setAddress call that Draco18s asked for earlier. – scottwinch Jun 21 '17 at 21:29