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 badkraft · May 26, 2017 at 06:09 PM · meshmesh renderer

Why is the mesh not rendering?

I am working through a tutorial here. I think I can share the package through my google drive for convenience.

I have set up a scene that looks like this:
hexgrid scene

The subject object is HexGridController and three objects that are disabled: center_fill, Backdrop, DiagnosticDisplay.

The grid controller is an otherwise empty GameObject except for attached script:
controller properties

...and the HexGridController script:

 public class HexGridController : MonoBehaviour, IGridInterface {
 
     public float cellWidth = 50F;
     public HexOrientation cellFacing = HexOrientation.Acute;
     public int cellCols = 20;
     public int cellRows = 14;
     public float degOffset = 0.0F;

     // ... snipped IGridInterface implementations
 
     // Use this for initialization
     private void Start () {
         print("Hexagonal Grid Controller started");
 
         print("hex vertices:");
         int idx = 0;
         foreach(var vert in vertices){
             print(string.Format("\t[{0}]: {1}", idx, vert.ToString()));
             ++idx;
         }
     }
 
     #region    HiddenInInspector: vertices, uv, triangles
     [HideInInspector]
     public static Vector3[] vertices = new Vector3[]
     {
             new Vector3(0f, Hexagon.floor, 1f),        //    north
             new Vector3(1f, Hexagon.floor, .5f),    //    northeast
             new Vector3(1f, Hexagon.floor, -.5f),    //    southeast
             new Vector3(0f, Hexagon.floor, -1f),    //    south
             new Vector3(-1f , Hexagon.floor, -.5f),    //     southwest
             new Vector3(-1f, Hexagon.floor, .5f),    //    northwest
     };
 
     [HideInInspector]
     public static Vector2[] uv = new Vector2[]
     {
         new Vector2(0.5F,1),    //    north
         new Vector2(1,0.75F),    //    northeast
         new Vector2(1,0.25F),    //    southeast
         new Vector2(0.5F,0),    //    south
         new Vector2(0,0.25F),    //     southwest
         new Vector2(0,0.75F),    //    northwest
     };
 
     [HideInInspector]
     public static int[] triangles = new int[]
     {
         1,5,0,
         1,4,5,
         1,2,4,
         2,3,4
     };
     #endregion
 }

And finally, HexGrid is a GameObject with the following script attached:

 public class Hexagon : MonoBehaviour {
     private MeshRenderer meshRenderer;
 
     public const float floor = 0;
 
     public HexGridController grid;
     public Texture texture;
 
     // Use this for initialization
     private void Start () {
         print("Hexagon started");
 
         HexGridController.vertices[0] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(1+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(1+0.5)/6))));
         HexGridController.vertices[1] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(0+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(0+0.5)/6))));
         HexGridController.vertices[2] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(5+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(5+0.5)/6))));
         HexGridController.vertices[3] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(4+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(4+0.5)/6))));
         HexGridController.vertices[4] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(3+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(3+0.5)/6))));
         HexGridController.vertices[5] = new Vector3((grid.cellWidth * Mathf.Cos((float)(2*Mathf.PI*(2+0.5)/6))), Hexagon.floor, (grid.cellWidth * Mathf.Sin((float)(2*Mathf.PI*(2+0.5)/6))));
 
         SetUpMesh();
     }    
     
     private void SetUpMesh() {
         MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>();
         gameObject.AddComponent<MeshRenderer>();
         meshRenderer = gameObject.GetComponent<MeshRenderer>();
 
         Mesh mesh = new Mesh();
         //vertices
         mesh.vertices = HexGridController.vertices;
         //triangles
         mesh.triangles = HexGridController.triangles;
         //UV vectors
         mesh.uv = HexGridController.uv;
      
         //recalc for lighting
         mesh.RecalculateNormals();
  
         //game object's mesh filter
         meshFilter.mesh = mesh;
  
         //set to null when not testing
         meshRenderer.material.mainTexture = texture; 
     }
     
     private void Update () 
     {
         
     }
 
     private void OnDestory()
     {
         Object.Destroy(meshRenderer.material);
     }
 }


hexgrid-controller-properties.png (12.8 kB)
hexgrid-construction-scene.png (5.9 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 badkraft · May 31, 2017 at 09:25 PM 0
Share

If you want developers to ask questions here (first as opposed to others, e.g., StackOverflow), maybe you should focus on answering the questions. I will add a link to my question on StackOverflow where my question at least received comments which led me in a direction to solve the problem myself. Thanks!!!

1 Reply

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

Answer by badkraft · May 31, 2017 at 09:27 PM

Since no one else provided any hint of an explanation or attempt to help, here is what I did to resolve the problem.

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

109 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 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

How to make mesh render objects overlay UI? 1 Answer

i dont see the sprite mesh in the list 2 Answers

How to make adjacent meshes look like they were joined? 0 Answers

Empty mesh with vertices and triangles 0 Answers

How can I layer images and mesh? 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