- Home /
Game keeps locking up "deleted gameObject" in hierarchy
So this script just checks after every movement if Im still on a cube on the grid. Now only SOMETIMES when the level is reset my game keeps resetting I assume because my boolean doesn't change. It doesn't do this because I'm moving too fast or ANY reason i can figure out I've been trying to troubleshoot doing the same thing over and over but only sometimes it happens at random occasions. It also sometimes locks up when I move to a different scene. In the hierarchy all my game objects are deleted and says "deleted gameObject" Any Ideas?
var floorCol : boolean = false;
function OnCollisionEnter(coll: Collision){
if(coll.gameObject.tag=="floor"){
floorCol=true;
}
}
function OnCollisionExit(coll: Collision){
if(coll.gameObject.tag=="floor"){
floorCol=false;
}
}
function Update(){
if(floorCol == false){
Debug.Log("reset");
floorCol=true;
Application.LoadLevel(Application.loadedLevel);
}
else if(floorCol==true){
Debug.Log("no reset");
}
}
Answer by Uldeim · Nov 07, 2014 at 03:55 AM
I don't really think there's enough information there (though I could be wrong), but it seems possible to me that the collision isn't firing before the first Update() call on whatever has this script attached.
Now, I don't really know much about Unity's internal bits and whether the physics engine and Update calls might have timing issues like that, but try something like:
if (floorCol == false)
{
Debug.Log("Floating...");
floatingCubeCount++;
if (floatingCubeCount > 15)
{
Debug.Log("reset");
floorCol = true;
Application.LoadLevel(Application.loadedLevel);
}
}
else //no real need for the 'else if' here
{
Debug.Log("We're all fine here now... how are you?");
}
Then, if you occasionally see a few "Floating..."s before whatever, that's probably the issue, and hopefully the delay should fix it anyways.
Your answer
![](https://koobas.hobune.stream/wayback/20220613170748im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Where is a good place to start Developing my Game? 5 Answers
Player Rotation 1 Answer
Teleport enemy after player collides with an object? 0 Answers
Help with array collision script ! 0 Answers