system
1
Hi there!
Can’t understand why is that happening:
I have a prefab, “objectPrefab”.
It has an attached script, Object.cs with the following code:
public int count = 0;
public void Action()
{
if(count == 0)
{
do Action2();
count++;
}
}
I instantiate an object of that prefab in other code.
The object and the prefab both have “count”= 0.
I call “Action()” with a button and it succesfully calls “Action2()”.
However, the instantiated object has “count” = 0 (which is correct) but the prefab has “count” = 1 (!) and changes to the prefab save after I restart the app!
So the next time I start the app, the object has “count” = 0 and the prefab has “count” = 1 and the button doesn’t work! As if it looks into the prefab’s “count”, not the object’s!
What am I doing wrong?
system
2
Turned out I had my “objectPrefab” placed into the button’s “OnClick” menu.
Doesn’t make any sense to me though: why would anyone wanted to interact with a prefab(!) with a button in exange to not beeing able to place actual instantiated objects into that button’s menu (as they do not exist untill you start the app).
Solved via adding “OnClick” listener to the button (linking the actual object, not the prefab) with script, which is kinda stupid.