Unity Editor Freezing

So, I’ve ran into a new kind of bug. Rather than just mess with the game, it freezes the entire editor, and I have to use Task Manager to force quit it and then reopen it. Using Debug.Log, I managed to track it down to stopping at a specific point in my code, whenever a specific if() statement comes up as true.

 if (collisionInfo.CompareTag("Wall"))
        {
             if (collisionInfo.transform.position.x >= gameObject.transform.position.x)
             {
                 canClimbR = true;
             }
        }

        if (collisionInfo.CompareTag("Wall"))
        {
            if (collisionInfo.transform.position.x <= gameObject.transform.position.x)
            {
                canClimbL = true;
            }
        }

for some reason, whenever the trigger I have set up enters a 2D collider attached to a game object with the “Wall” tag, the editor freezes.The weird thing is, it works fine for detecting game objects with other tags, such as “Ground” or “Enemy”.

Hi William,

That sounds indeed strange. You tested your code with another tag, and it worked? What else is there in the environment of this code? A loop?

// it's sufficient to compare the tags once
if (collisionInfo.CompareTag("Wall"))
{
    canClimbR = collisionInfo.transform.position.x >= gameObject.transform.position.x;
    canClimbL = collisionInfo.transform.position.x <= gameObject.transform.position.x;
}

I’m not exactly sure what problem your code solves but when the two sides in the condition are equal, both canClimbR and canClimbL get set to true. Maybe that case causes an endless loop somewhere?

Not exactly. So, I have to check other game objects for there tags so the player can do various things, such as only be able to jump when it’s on an object with the “Ground” tag. those parts work fine. But, well, long story short this is the code I’m using now.

            Debug.Log("About to check");
            if (collisionInfo.CompareTag("Tall Line"))
            {
            Debug.Log("The checking is working now");
                if (collisionInfo.transform.position.x > gameObject.transform.position.x)
                {
                    canClimbR = true;
                }
                else if (collisionInfo.transform.position.x < gameObject.transform.position.x)
                {
                    canClimbL = true;
                }
            }

I’m not entirely sure what’s going on with it now, so I’m not going to attempt to describe it yet. Each time I do I run another test and find out what I thought before was wrong. Unfortunately, I’m leaving for my grandparents house until Tuesday, and I won’t be able to do more tests to try and understand it until I get back. So I’m not going to be online until then, sorry.

Maybe it’s a good idea to “forget” the problem for a couple of days. :slight_smile:

Finally! I’m back, and I finally got it to work. Apparently the part of the code we were thinking over wasn’t what was broken after all, and for some reason even though the Debug.Log I had written wasn’t being run, the code changing the variables was. I managed to fix it after messing with the code where the variables were being used. I think what MIGHT have happened was it was getting stuck in a loop where the player was always frozen in place. I’m worried Debug.Log isn’t ran how I think it’s ran though, and that it’s called after the rest of the code is or something. So I can’t accurately use it how I was.

Good job on fixing the problem! :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms