I have a strange problem with my script’s Start() function being called constantly, even in a situation where it should be impossible. Another problem seems to be with my script’s variables updating(they simply aren’t).
To start, I have written a script that will, when called, build a room out of cubes and quad objects, and decorate it with a prefab. When building the room, making the cubes and quad objects seems to go just fine. However, when retrieving the prefab, that’s when things begin to go wrong, and the function where the room building was called, the Start function gets called over and over and over again. The same thing happens if I do so in the Update function, even if I set variables so that the room building operation occurs only once, the variables themselves never update.
I’ve tracked the problem down to the prefab used in decorating the room. It is a fairly large prefab made up of other prefabs and if I use a different prefab, this problem doesn’t occur.
Oddly enough, I haven’t been able to reproduce this glitch ever since I erased the original prefab I used. I’m now using an even larger prefab to recreate the glitch(where the first prefab was about 20 items large, the one I’m using now is over 100!), yet it refuses to happen again! I mean, I’m happy it’s gone, but I’m very bothered that I don’t know what caused it.
Below is the code for my script’s start function. Know that there is no where in any of my code where I create any other script object, nor do any of my prefabs have this script as a component.
bool bInitialized = false;
void Start ()
{
if (!bInitialized) {
bInitialized = true;
Room meatRoom = CustomRooms.MeatRoom (12);
meatRoom.BuildRoomInUnity ();
meatRoom.BuildCubeWalls ();
Debug.Log ("Building Room");
}
TestGames.levelSize = levelSize;
}
I use C#, MonoDevelop, and Unity 4.5.5.
I now ask, is there any known reason or setting that might cause a script’s Start() function to be called over an over again, and is there any known reason why a script’s variables might fail to change, even when explicitly set?