- Home /
Unity crashes on certain collisions
So I'm working on an upwards scrolling space shoot em up.
The Player has a character controller and rigidbody and this code regarding the collisions (please ignore CamelCase errors and indenting)
function OnCollisionEnter(hit : Collision)
{ var targeto = hit.gameObject;
if (targeto.tag == ("Enemy"))
{
targeto.GetComponent(typeof (enemyBehaviour)).TakeDamage(100);
Boom();
}
}
Whenever the player collides with an enemy he damages the enemy ship and explodes. Now the strange thing is, sometimes the entire editor crashes when I do test this. The strange part is that it only happens sometimes, it seems to be only a second type of enemy, although they have all the exact same components and the same script, OR if I first shot an enemy before crashing into another.
if (Input.GetButtonDown("Fire1"))
{
var shotpos1= new Vector3(transform.position.x+0.5,transform.position.y,transform.position.z+2);
var shotpos2= new Vector3(transform.position.x-0.5,transform.position.y,transform.position.z+2);
var shot1 = Instantiate(shot, shotpos1, transform.rotation);
var shot2 = Instantiate(shot, shotpos2, transform.rotation);
}
}
(and in the bullets script)
function OnCollisionEnter(collision : Collision)
{
var targeto = collision.gameObject;
if (shotByPlayer == 1){
if (targeto.tag == ("Enemy"))
targeto.GetComponent(typeof (enemyBehaviour)).TakeDamage(shotPower);
Destroy(gameObject);
}
{
Is the problem perhaps that OnCollisionEnter belongs to colliders and not character controllers?
or perhaps that Boom() involves deleting the the player gameobject, i.e. screwing with the very thing unity is acccessing?
edit: ok so apparently it only crashes if the player is moving manually. If the collision is due to the scrolling then its all fine, but if I ram the enemy everything crashes
I've removed the destroy gameobject part of Boom() seemed fine for a while but after ram$$anonymous$$g a few enemys it crashed.. so "or perhaps that Boom() involves deleting the the player gameobject, i.e. screwing with the very thing unity is acccessing?" is unfortunately not it :(
I'm experiencing the same problem. I have a projectile that seems to cause Unity to freeze up sometimes when it hits a kinematic block. It also freezes on the android build.
Not sure exactly how to recreate it, seems very intermittent.
Answer by Ehren · Oct 01, 2010 at 09:23 PM
I'm having a similar issue. In my case it seems to only happens when I collide in an up-and-to-the-left direction with the object that gets de-activated.
I'd suggest trying to create a level where it happens every time. Then file a bug report and attach the project.
Your answer
Follow this Question
Related Questions
Turn On - off character controller script, is there a way?? 3 Answers
how to make player collide for swimming 1 Answer
Character glitching on Ragdoll 0 Answers
How to stop CharacterController during Collider's moving? 0 Answers
Prevent player to walk over items, but without limiting their ability to place other items on it 1 Answer