• 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
Question by Mr_Potato342 · Mar 09 at 09:52 AM · meshprocedural meshprocedural generation

cant see mesh

I am generating a mesh with custom amount of sub-divisions, known as side length in the code, when I click on the mesh filter I see that the amount of vertices, triangles and uvs, but no mesh, not even in wireframe, here is the code if you need to see it, it is executable in edit mode

 using System.Collections.Generic;
 using UnityEngine;
 
 [ExecuteInEditMode]
 public class TerrainObj : MonoBehaviour
 {
     [SerializeField] private List<int> Triangles;
     private Mesh mesh;
     [Range(3, 9999)]
     [SerializeField] private int sideLength;
     [SerializeField] private bool generateNewMesh;
     [SerializeField] private List<Vector3> Vertices;
     [SerializeField] private List<Vector2> UVs;
 
     private void Awake()
     {
         sideLength = 2;
         GetComponent<MeshFilter>().mesh = new Mesh();
         mesh = GetComponent<MeshFilter>().sharedMesh;
     }
 
     private void Update()
     {
         if (generateNewMesh == true) Generate();
     }
 
     private void Generate()
     {
         generateNewMesh = false;
         Triangles = new List<int>();
         Vertices = new List<Vector3>();
         UVs = new List<Vector2>();
 
         for (int x = 0; x < sideLength; x++)
         {
             for (int z = 0; z < sideLength; z++)
             {
                 Vertices.Add(new Vector3(x, 0, z));
 
                 Triangles.Add(x + z);
                 Triangles.Add(x + (z + 1));
                 Triangles.Add((x + 1) + z);
 
                 Triangles.Add(x + (z + 1));
                 Triangles.Add((x + 1) + z);
                 Triangles.Add((x + 1) + (z + 1));
                 Debug.Log("E");
             }
         }
 
         foreach(Vector3 vec in Vertices)
         {
             UVs.Add(new Vector2(vec.x, vec.z));
         }
 
         UpdateMesh();
     }
 
     private void UpdateMesh()
     {
         mesh.Clear();
         mesh.SetVertices(Vertices);
         mesh.SetTriangles(Triangles, 0);
         mesh.SetUVs(0, UVs);
     }
 }

Comment

People who like this

0 Show 0
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

1 Reply

  • Sort: 
avatar image

Answer by BoxDudeStudio · Mar 09 at 09:59 PM

It seems like you're on the right track, but there could be some things going wrong that I noticed. One possibility is that the mesh is not being properly assigned to the MeshFilter component. In your code, you're creating a new Mesh object in the Awake() method, but then in the UpdateMesh() method you're updating the mesh's vertices, triangles, and UVs. This might be clearing the mesh and making it disappear. Another possibility is that the camera might not be in the right position to see the mesh. Have you tried moving the camera around to see if the mesh is visible from a different angle? If neither of these things work, it might be helpful to add some debug statements to your code to see if there are any errors or unexpected behavior happening.

Comment

People who like this

0 Show 0 · 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

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

Manual culling of voxel faces? 0 Answers

Generating sectors around nodes 0 Answers

Procedurally Generated mesh not rendering all triangles,Procedurally generated mesh isn't rendering all triangles? 1 Answer

Do i have to use shared vertices if i want my proceduraly generated mesh to look smooth? 1 Answer

Procedural mesh with texture atlas, how to get rid of material artifacts? 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