- Home /
Unity Editor crashes from a seemingly trivial piece of knockback code?
else
{
Debug.Log("Started attack");
if (setDirection == false)
{ coll.attachedRigidbody.velocity = new Vector2(coll.transform.position.x - transform.position.x, coll.transform.position.y - transform.position.y).normalized * knockback; }
else
{ coll.attachedRigidbody.velocity = direction.normalized * knockback; }
usedColls.Add(coll);
Debug.Log("Finished Dealdamage function");
}
Hey, so, my unity editor crashes whenever this piece of code gets executed. The weird thing is, when it's executed, it does not execute the first Debug.Log,but then DOES execute the knockback function once before crashing the game entirely. The other code gets run through fine. I already debugged those parts. But once it hits this part, the entire editor freezes, sucks up 4g of ram, and then either I end it through task manager or I wait a few minutes and the editor ends itself.
I highly doubt that this is what's crashing your unity. Can you show the entire script please.
Well, I did run tests to see where things went wrong and what parts did still run. I'll post the code in a bit, but to explain how it works:
I have a Switch in the FixedUpdate function. This Switch keeps track of what state the player is in. While it's in a state, the corresponding function gets executed.
The attack function gets run for 40 frames. During these 40 frames the DealDamage function gets run 3 times per frame (once for each hitbox, which isn't very efficient, but I couldnt get the function to work by giving an array/list of hitboxes). I thought it might be crashing cause the load is too heavy, but it doesn't seem like THAT much to me.