• 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
1
Question by Carson7634 · May 09, 2014 at 12:40 AM · importblenderrenderbounds

(GameObject).renderer.bounds.size.(axis) returns 0.

Hello Unity Answers,

I am doing this tutorial for making a hex grid.

He provides code to make a 10 X 10 hex grid. When I run the test, the calls to the renderer bounds are returning zero, causing all hex tiles to be created on top of each other.

I imported a hex shaped mesh from blender, removed the animator component that came with it, and added a mesh renderer component.

Could anyone give me some ideas as to why this may be happening, and how to correct it?

Here is the code:

 using UnityEngine;
 using System.Collections;
  
 public class GridManager: MonoBehaviour
 {
     //following public variable is used to store the hex model prefab;
     //instantiate it by dragging the prefab on this variable using unity editor
     public GameObject Hex;
     //next two variables can also be instantiated using unity editor
     public int gridWidthInHexes = 10;
     public int gridHeightInHexes = 10;
  
     //Hexagon tile width and height in game world
     public float hexWidth;
     public float hexHeight;
  
     //Method to initialise Hexagon width and height
     void setSizes()
     {
         //renderer component attached to the Hex prefab is used to get the current width and height
         hexWidth = Hex.renderer.bounds.size.x;
         hexHeight = Hex.renderer.bounds.size.z;
     }
  
     //Method to calculate the position of the first hexagon tile
     //The center of the hex grid is (0,0,0)
     Vector3 calcInitPos()
     {
         Vector3 initPos;
         //the initial position will be in the left upper corner
         initPos = new Vector3(-hexWidth * gridWidthInHexes / 2f + hexWidth / 2, 0,
             gridHeightInHexes / 2f * hexHeight - hexHeight / 2);
  
         return initPos;
     }
  
     //method used to convert hex grid coordinates to game world coordinates
     public Vector3 calcWorldCoord(Vector2 gridPos)
     {
         //Position of the first hex tile
         Vector3 initPos = calcInitPos();
         //Every second row is offset by half of the tile width
         float offset = 0;
         if (gridPos.y % 2 != 0)
             offset = hexWidth / 2;
  
         float x =  initPos.x + offset + gridPos.x * hexWidth;
         //Every new line is offset in z direction by 3/4 of the hexagon height
         float z = initPos.z - gridPos.y * hexHeight * 0.75f;
         return new Vector3(x, 0, z);
     }
  
     //Finally the method which initialises and positions all the tiles
     void createGrid()
     {
         //Game object which is the parent of all the hex tiles
         GameObject hexGridGO = new GameObject("HexGrid");
  
         for (float y = 0; y < gridHeightInHexes; y++)
         {
             for (float x = 0; x < gridWidthInHexes; x++)
             {
                 //GameObject assigned to Hex public variable is cloned
                 GameObject hex = (GameObject)Instantiate(Hex);
                 //Current position in grid
                 Vector2 gridPos = new Vector2(x, y);
                 hex.transform.position = calcWorldCoord(gridPos);
                 hex.transform.parent = hexGridGO.transform;
             }
         }
     }
  
     //The grid should be generated on game start
     void Start()
     {
         setSizes();
         createGrid();
     }
 }

Comment
Add comment · Show 2
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 Thomas.Amundsen · Aug 10, 2014 at 02:53 AM 0
Share

I am having the same problem. Did you ever figure this out?

avatar image Tanoshimi2000 · Sep 26, 2014 at 01:06 PM 0
Share

Same problem here. Contrary to what most people are posting, importing a mesh does not automatically get you a renderer or collider, so you don't get bounds information. I wrote an AssetPostprocessor that adds a $$anonymous$$eshRenderer and a BoxCollider when it's imported. Again, the community would have you believe that those will automatically fit to the mesh; however, I was still getting zeros for bounds on either renderer or collider. Still haven't figure out how to get the bounds of an fbx model.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Any Blender users out there? Where are my materials/Renderers? 1 Answer

Why can't I import animations? 1 Answer

Blender Nromal Problem 0 Answers

I import a model from blender to unity,but it is always showed in mirror 4 Answers

how do i import an animation from blender 2 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