I can't figure out how to refer to the size of a particular mesh.
The mesh is created through
.BakeMesh(), then a box collider is added. Unfortunately the box collider has a scale of 1 by 1 by 1, regardless of how big the mesh I'm adding it to seems to be.
This doesn't match my understanding of how creating a box collider should work, so I've set up a Debug.Log that outputs the mesh size.
Here the plot thickens. The mesh's size just comes back at
0, 0, 0.
My attempts at getting the size of the object are as follows:
objectToMeasure.GetComponent<Renderer>().bounds.size; objectToMeasure.GetComponent<MeshFilter>().mesh.bounds.size objectToMeasure.GetComponent<MeshFilter>().sharedMesh.bounds.size;
Assuming I'm referring to the size of the object in the correct way, this seems like it must be an issue created by baking the object. Do I need to wait a frame (via starting a coroutine) before trying to access the size of the object, or am I referring to the wrong component of the object, or is the BoxCollider setting it's size based on objectToMeasure's scale rather than it's size in the world?
I feel sure that objectToMeasure.GetComponent().mesh.bounds.size; should be right, since the script I use to bake to the mesh is: meshToBake.BakeMesh(meshToMeasure.GetComponent().sharedMesh);
I've been driving myself to the edge of sanity for 24 hours with this script not working, so advice is greatly appreciated.