- Home /
Checking Collision on instantiated object
I have a script where I am trying to place items. What I have currently is I create and instance of the item, move it to where I want to place it and then I want to make sure it's not colliding. Like this :
GameObject theItem = Instantiate(prefab, Vector3.zero, Quaternion.identity);
theItem.transform.position = placement.position;
theItem.rigidbody.SweepTestAll(Vector3.up,0f);
This does not work, as the sweepTest always returns 0 collisions, so I tried having a script on theItem that tracks collisions and updates a isColliding member, like this :
GameObject theItem = Instantiate(prefab, Vector3.zero, Quaternion.identity);
theItem.transform.position = placement.position;
theItem.GetComponent<CollisionManager>().isColliding;
This also fails, BUT the is colliding does get turned on, just not until the next frame.
Is there a way I can check the complex colliders against other complex colliders all in the same frame? It seems all the unity built in methods have a delay to them. I might have to check against multiple placements if they are colliding as well.
You could try making it a coroutine, and yielding the next fixed update, but that's not exactly a solution (more a workaround).
Yeah I thought about that, but I ran into 2 problems. 1. This is a non-monobehavior class and 2. I really want it to be instant as it's part of a procedural generation function.