Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Parallaxe · Oct 17, 2013 at 11:27 AM · prefabsizeboundsheight

Size of a prefab instance is always (0,0,0)

Hi there

I have prepared a simple prefab that represents my player character. I have instantiated this prefab and now want to find out the position and height of the instance via a C# script. Determining the position works fine (In the following snippets "_character" is my local variable, holding the game object = instantiated prefab):

 Debug.Log("Position: " + _character.transform.position);

Displays correctly as:

 Position: (2.2, 0.0, -3.0)


 

But it won't work for the size of the instance:

 Debug.Log("Size: " + _character.renderer.bounds.size);

Displays as:

 Size: (0.0, 0.0, 0.0)

The instance has a component "Mesh Renderer" attached to it.

What am I doing wrong?

Comment
Add comment · Show 6
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 ShadoX · Oct 17, 2013 at 11:48 AM 0
Share

This isn't exactly an answer, but if the object has a collider - http://docs.unity3d.com/Documentation/ScriptReference/Collider-bounds.html ?

collider.bounds.size

avatar image Parallaxe · Oct 17, 2013 at 11:54 AM 0
Share

Hi ShadoX. Thanks a lot for your comment (-:

Yep, I have indeed a collider attached. And "collider.bounds.size" works just fine, displaying the correct values. I'm only struggling with "renderer.bounds.size" which keeps displaying (0,0,0).

avatar image whydoidoit · Oct 17, 2013 at 12:35 PM 1
Share

I guess it's not set until the item is rendered? Perhaps use the mesh bounds and offset them to the position?

avatar image Parallaxe · Oct 17, 2013 at 01:10 PM 0
Share

You're a genius, whydoidoit, your guess is absolutely right. I tried to deter$$anonymous$$e the size whilst Unity has not yet completely finished rendering the game object. Thank you so much (-:

avatar image meat5000 ♦ · Oct 17, 2013 at 01:14 PM 0
Share

Convert to answer :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Parallaxe · Oct 17, 2013 at 01:13 PM

Hi there

"whydoidoit" pointed me in the right direction, his guess was absolutely correct:

Initially I had tried to determine the size at a point in time, where Unity did not yet have completely finished rendering the respective game object. Moving the whole thing to another code position, where I was sure that Unity had finished rendering all game objects, did the trick.

Thanks a lot to "whydoidoit"! Question has been answered.

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

17 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

Related Questions

How to set RectTransform size relative to the size of the textbox? 1 Answer

How can I determine an object of prefab's size (for positioning when instantiating them) 2 Answers

Prefabs with sprites, make them all same size 0 Answers

Determining the size of a prefab 0 Answers

Array of prefabs with different sizes stick to each other 0 Answers


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