how would I set a renderers bounds (center and extents) in script? the inspector provides access to it, but I know its read-only when I try to do the same in a script. Thanks.
Jul 30 '12 at 10:17 AM
Renderer.bounds just tells you the bounds of the renderer. This depends on the object it is rendering. You can't set the bounds, why would you? The bounds are a result of the objects position / scale / rotation.
Jul 30 '12 at 10:32 AM
there are some issues with the model/rig that require manual adjustments (and unfortunately fixing the rig is not an option)
Well, if you want to set the bounds manually, you have to set
Mesh.bounds, not Renderer.bounds. The renderer is just a component which renders the mesh. The Mesh represents the actual data.
tried that to no avail, thanks for the suggestion!
I just tried it myself and it works like expected... When i insert a cube and change the mesh bounds, the isVisisble flage is changing like expected.
What kind of problems do you have? Usually the bounds are calculated correctly for any kind of mesh, so where or how do you experience problems?
Again, Renderer.bounds is determined at runtime. It's not stored anywhere. It represents the axis-aligned-bounding-box (AABB) that encloses the rotated mesh.bounds. mesh.bound can be changed manually, but Renderer.bound is always an AABB, so when the object is rotated, it will be larger.
How does your object look like? If the mesh is already rotated in local space, the mesh.bounds will already be too large. The bounds can't be rotated to match your object shape. Mesh.bounds is a local AABB and Renderer.bounds a worldspace AABB.
If you are creating a mesh a runtime, then you might be looking for Mesh.RecalculateBounds. Otherwise, as @Bunny83 said, there is not need to set the bounds yourself.
Jul 30 '12 at 10:37 AM
thanks for the replies, but there are issues with the model and rig I received leading to my need to do some manual adjustments. I was hoping to automate this, but I guess that isn't possible (and neither if fixing the rig).
I tried that but since the model/rig are at fault, it just recalculates the same bad bounds and fixing the rig is not currently an option.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
Once you sign in you will be able to subscribe for any updates here
Answers and Comments
The best place to ask and answer questions about development with Unity. Check out our FAQ for more information.
To help users post good questions and use the site effectively we have posted a tutorial video. Please check it out.
asked: Jul 30 '12 at 10:17 AM
Seen: 1083 times
Last Updated: Aug 01 '12 at 06:57 AM
How do I check if an object is completely visible?
Generate Bounding Box, In Game
Text with fixed size in viewport
Can't convert Bounds from world coordinates to local coordinates
Instantiate Left-Edge of Prefab at Right-Most Edge of Another
Bounds larger than expected
TextMesh.renderer.bounds.extents not 100% accurate?
Accessing material of particle renderer??
How do I play a full screen video?