Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jul 23, 2017 at 09:13 PM by agencebrunel for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by agencebrunel · Jul 23, 2017 at 07:29 PM · instantiatechildrenboundsworldspaceencapsulation

Are my bounds right world position in this case ?

  • I use script on prefab to instantiate many block to make rooms.

  • I use a script to make bouds = of all instantiated children block of piece.

  • My debug give good value ( i think ) in console.

  • But is the white draw good value ? Why all go to 0 0 0 world ?

alt text

Script is here :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class bound : MonoBehaviour {
   void OnDrawGizmos()
     {
 
         Bounds bounds = GetChildRendererBounds(gameObject);
         Gizmos.DrawWireCube(bounds.center, bounds.size);
         Debug.Log(bounds +","+ gameObject);
     }
 
     Bounds GetChildRendererBounds(GameObject go)
     {
         Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
 
         if (renderers.Length > 0)
         {
             Bounds bounds = renderers[0].bounds;
             for (int i = 1, ni = renderers.Length; i < ni; i++)
             {
                 bounds.Encapsulate(renderers[i].bounds);
             }
             return bounds;
         }
         else
         {
             return new Bounds();
         }
     }
 }
03.png (341.2 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image agencebrunel · Jul 23, 2017 at 08:09 PM 0
Share

Ok my bounds are wrong in console to, center is center of bounds we show with white draw.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jul 23, 2017 at 09:08 PM

Your combined bounds look like they somehow include the world origin as well. However your code specifically avoids this since you correctly start with the bounds of the first and then combine with the remaining.

I think your problem is that your parent object also has a MeshRenderer but that doesn't seem to have any mesh. That's why the bounds of the parent most likely is an empty bounds located at worlds "0,0,0".

"GetComponentsInChildren" also returns components on the actual object, not only components on children. So you also process the MeshRenderer on your parent object.

Since you don't have a MeshFilter with an actual mesh to render on your parent you might want to simply remove the MeshRenderer from your parent as it serves no purpose besides causing trouble.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image agencebrunel · Jul 23, 2017 at 09:12 PM 0
Share

Thanks so mutch ! That was that. I have delet on my script the mesh add component to the parent, and my bounds are all good.

Follow this Question

Answers Answers and Comments

82 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Dynamically creating a box collider for an object with multiple, rotated, and scaled mesh renderers 0 Answers

Terrain Generator Problem: Index is less than 0 or more than or equal to the list count 1 Answer

Getting Collider2D.bounds.extents to update immediately (2D) 0 Answers

Set bounds of collider added at runtime 1 Answer

Instantiate GameObjects inside a collider 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges