Variables in a script on a prefab do not store runtime changes
Hello, long time reader - first time poster.
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 script contains a simple function:
setAddress(string str)
address = str; //address is a string variable defined for the script
Debug.Log("you set address " + address); //called after address is set.
In the "TownCreator" script, after the prefab is instantiated, I call that function and pass the address to it. 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. !Bueno!
Now for the not bueno; 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 BLANK! I added a similar Debug.Log at that point, and it also tells me that "address" on the clone is blank. :-(
I believe the code is:
Text.text = address; //I switched it out to "ADDRESS" - and that works.
Any ideas why the script on the prefab clones is not storing the values? I can post code later, if it helps (I am at my day job) - but I figure the debug logs showing a value and the UI popping up mean (and the hard coded "ADDRESS" working) that the code is fine - but address is not sticking.
Thanks in advance!