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 /
  • Help Room /
avatar image
0
Question by samuelthe2nd · Apr 09, 2016 at 02:05 PM · rendererheightwidthempty game objectrenderer bounds

How to find width and height of an gameobject with no renderer?

Hi so I've been developing some code and have encountered an issue. For those familiar to AS3 you'd know that if you have for example:

var _gmCase:MovieClip() = new MovieClip();
var _gm1:MovieClip = new Object1(); //has a width and height of 5
var _gm2:MovieClip = new Object2(); //has w width and height of 5

_gmCase.addChild(_gm1);
_gm1.x =0;
_gmCase.addChild(_gm2);
_gm2.x = _gm1.width + 10;

trace(_gmCase.width); //returns 20. // includes the width and distance between furthest object to the left and furthest object to the right.

What I'm trying to get in unity is access the "_gmCase.width", but its an empty GameObject width "_gm1" and "_gm2" attached as children in the Hierarchy and has no Renderer or any other component of any sort apart from my script which is trying to access its width.

"_gm1" and "_gm2" are prefabs and have Renderers and meshes as well as Colliders attached to them.

Please note that "_gmCase.GetComponent().bounds.size.z;" tells me that there is no Renderer attached to the object.

Anyone know of a way to get the Gameobject's width without any components attached to it?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Oribow · Apr 10, 2016 at 11:48 PM

OK, if scrambled a script together for you. It only works in 3d through. But it could be changed to 2d.

 public static Bounds GetRealSize(GameObject parent)
     {
         MeshFilter[] childrens = parent.GetComponentsInChildren<MeshFilter>();
         Debug.Log(childrens[0].mesh.bounds.size+"*" + childrens[0].transform.localScale+ " / 2 + "+ childrens[0].transform.position);
 
         Vector3 minV = childrens[0].transform.position - MultVect(childrens[0].mesh.bounds.size, childrens[0].transform.localScale) / 2;
         Vector3 maxV = childrens[0].transform.position + MultVect(childrens[0].mesh.bounds.size, childrens[0].transform.localScale) / 2;
         Debug.Log(maxV);
         for (int i = 1; i < childrens.Length; i++)
         {
             maxV = Vector3.Max(maxV, childrens[i].transform.position + MultVect(childrens[i].mesh.bounds.size, childrens[i].transform.localScale) / 2);
             minV = Vector3.Min(minV, childrens[i].transform.position - MultVect(childrens[i].mesh.bounds.size, childrens[i].transform.localScale) / 2);
             Debug.Log(maxV);
         }
         Vector3 v3 = maxV - minV;
         return new Bounds(minV + v3 / 2, v3);
     }
 
     private static Vector3 MultVect(Vector3 a, Vector3 b)
     {
         a.x *= b.x;
         a.y *= b.y;
         a.z *= b.z;
         return a;
     }
Comment
Add comment · 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
0

Answer by m3Dium · Aug 30, 2016 at 08:00 PM

@Oribow: you could have used Vector3.Scale(a, b), which does exactly the same as your MultVect method. Only to let it registered, as it can be useful for future readers.

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

56 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

Related Questions

TextureParameter, get width? 0 Answers

Getting width and height of gesture? 1 Answer

Canvas match width or height 1 Answer

How to get 2d camera width & height? 2 Answers

Find the Terrain Width and Height 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