Collision data stored in an array overwrites everything
Hi, this is my first time coming to actually ask my own question since I can't find it anywhere and don't really know what else to be checking. I'm currently using 2021.1 but it shouldn't be a bug? I have a script on a player object with a rigidbody and a collider:
private Collision[] collisionsArray = new Collision[10];
private void OnCollisionEnter(Collision collision)
{
for (var j = 0; j < collisionsArray.Length; j++)
{
if (collisionsArray[j] == null)
{
collisionsArray[j] = collision;
return;
}
}
}
I'm only ever able to have Collision data for one object, meaning that if I collide with a cube its fine, but when I collide with a sphere after that then every filled element in the array change to the sphere collision. I'm checking by debug.log (ing) the collisionsArray[j].gameObject.names. The only thing I can think of is that the array is storing a pointer to the collision reference but I've got no clue.
Comment