Problem is certain objects are not being detected by colliders. I am object pooling these gameobjects to not instantiate them at the moment. They are object pooled by waves, 20-30 objects per wave.
The problem is here: First wave - Everything gets detected by the collision of the collider.
Then the second and rest of the waves get ignored by the collider. Some may be detected but majority are all ignored. The second wave does not start until all the gameobjects in the first wave are setActive(false)
when they hit the collider in OnCollisionEnter
.
Nothing different is happening when disabling or enabling for object pooling, I checked both gameobjects in wave 1 and 2 and they are both the same, rigidbodies and colliders are all enabled with default settings since the first spawn.
What am I missing? Why is only first wave object pooled gameobjects working and not the reused ones.
private void OnCollisionEnter(Collision collision)
{
if (collision.transform.GetChild(0).gameObject.tag == "Enemy")
{
Debug.Log("P: " + collision.contacts[0].point + " | N: " + collision.contacts[0].normal);
// Allow ALL Enemies to not be stopped by Impact
Physics.IgnoreCollision(collision.collider, GetComponent<Collider>());
}
}
The object pooling code to spawn
GameObject enemy = ObjectPooler.SharedInstance.GetPooledObject("Enemy");
if (enemy!= null)
{
enemy.SetActive(true);
}
object pooling code to destroy
enemy.SetActive(false);
P.S. I had created another post about this problem but in that post I thought it was due to another problem but it has to be this problem because no matter how many objects I have in the first wave they all get detected. Only 2, 3, 4th wave get ignored. Only some in those waves get detected and my guess the ones that are detected are the new gameobjects that haven't been used by the object pool yet. Please help
When the enemy collides with Player(presumably) you are setting bot the collider to ignore each other. but when you respawn the enemy you are not resetting the ignorance between bot the colliders. you can do that by
Physics.IgnoreCollision(collision.collider, GetComponent<Collider>(), true/false);
where true mean collider will ignore each other and false mean collider will collide with each other.
Read more about Physics.IgnoreCollision at the link.