Validate Object Placement

Hi,

Just wanted to ask whether it’s possible to check for collisions between objects at runtime? At the moment I’m placing objects and I’m doing bounding box checks to see whether the object I’m placing overlaps any other existing object and if it does, I discard the new object and try to place another. This has worked fine.

With more advanced room shapes, bounding shapes are now much harder to set up. I would instead like to do a similar test using Mesh Colliders but I notice there’s not a way in script to check if an object is colliding as soon as its created. I’ve thought about using trigger callbacks but unless I’m mistaken a frame needs to before that callback will be used and I’m really trying to generate a lot of objects at once rather than over a period of time so this isn’t desirable.

So just wondered if there are any other suggestions?

Thanks,

Lukas

Before instantiating your object, you can put an empty at your target location and do a spherecast from it, so that the radius is a bit bigger than the object to be instantiated, then analyze the return to see if there would be collisions at the sampled location.

That’s not suitable as there’s not enough precision. I think my solution will be to split an object into a multiple colliders and use the bounds from each box collider to test if the object overlaps. With multiple box colliders, they can be used to represent smaller spaces and form the shape required all together. It would potentially work with the methodology you mentioned as well but I want as much stored with the prefab as possible.