Mesh bounds doesn't take into account the position nor scale

Hi,

I’m trying to know if an object is inside another one, and for this I was hoping to use the mesh.bounds and see if a given point was inside it. However, the mesh.bounds.Contains doesn’t take into account the object’s position nor if it has been scaled. Is this expected behaviour?

For example, if I have a cube 1x1x1, and I move it from (0,0,0) to (5,5,5) and I try to see if the mesh contains point (0,0,0), it will return true, even though they are apart from each other.

Regards,
Afonso

Mesh bounds are always in “local space”, i.e. the bounds you get when you loop over all the vertices and “bound” them. Thus they are per-mesh: for all objects that use this mesh, the bounds are the same. Hey, all those objects use the same mesh, so it should have the same bounds!

I think you should use Renderer’s bounds property; as that is per-object. And it does take scale, translation and whatnot into account.

1 Like

Oh, ok, I thought that mesh was bound to that specific object, and sharedMesh was the one that was common to all objects. Thanks for the explanation.

Regards,
Afonso