Bounding Box Size = 0 .

Hello everybody,

I have a problem that a cannot explain concerning the bounding box encapsulation. Here is the code I use to expand a father box using childs ones :

// Add Daugthers

		for(int k=0; k<selectedObjects.Count; ++k)

		{

			selectedObjects[k].HighLight(false);

			selectedObjects[k].Obj.transform.parent = father.Obj.transform;

			

			// Add the Box Collider  Bound

			father.Obj.renderer.bounds.Encapsulate(selectedObjects[k].Obj.renderer.bounds);

		}		

				

		Debug.Log("Father name : " 		   + father.Obj.name);

		Debug.Log("Father Bounding min : " + father.Obj.renderer.bounds.min);

		Debug.Log("Father Bounding max : " + father.Obj.renderer.bounds.max);

		Debug.Log("Father Bound : " 	   + father.Obj.renderer.bounds.size);

The problem is that my Bouding max size is the same that the min one, so the bounding box size is equal to 0. I do not undestand this behaviour.

I have already seen this topic :
http://forum.unity3d.com/viewtopic.php?t=4954&sid=1b438a9172c51c26fc4fe82add5ddc5f

But I still have the same problem.
Thank you very much for your answers.

Kind regards.

From my point of view it should work. You may try to replace

father.Obj.renderer.bounds.Encapsulate(selectedObjects[k].Obj.renderer.bounds);

by

father.Obj.renderer.bounds.Encapsulate(selectedObjects[k].Obj.renderer.bounds.min);
father.Obj.renderer.bounds.Encapsulate(selectedObjects[k].Obj.renderer.bounds.max);

It is not tested! Just an idea.

Still the same problem.

Logs :

Have you tried to Debug.Log the bounds.min and bounds.max in the for loop for all the children?

Yes and there are just like I suppose.

I just had a closer look on the issue. I am not sure if you can or even should modify the bounding box of a renderer. For me it does not make a lot of sense to do that. Could you explain why you want to change the renderer’s bounding box?
If you want to manipulate the bounding box, it is probably better to change the mesh’s bounding box. But that doesn’t make more sense from my point of view (as long as you don’t change the vertices of the mesh). It would help if you could explain the reason for why you want to do that.

Regards

Actually I use a empty object as parent to group some objects togethers. So, for instance, I’ll be abble to move several objects from just the father node. And I want that the bounding box of this empty object (the father) is the bounding box of all the objects which are grouped together. Does it make sens ?

But thanks for the answer, you’re right concerning the possibility to change the bound. I’ll derive gameObject and add a new bouding property to be abble to manage as I want.

It makes sense, but the bounding boxes are used for the rendering and are also optimized for that. So using it for other things is not always the best idea. As you said, using your own bounding property is probably a better solution.