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 norther · Jan 01, 2017 at 06:36 PM · mesh2d-platformermeshrenderermeshfilter

Code generated mesh not visible

Hi,

I'm doing a 2d side scroller and wanted to generate a mesh for the ground. I followed some advices from the net but I can't make the mesh visible.

I tried to solve it looking at the forum, I found many posts about but none of them solve my problem. I simplified the script to the moment where there is nothing else to simplify and it's still not working.

The mesh is not visible both in game and scene view (I checked while running the game). But when I double click the mesh in mesh filter componeni it is shown correctly in the preview window.

I thought it can be an issue of the graphic drivers but after updating them (i use Nvidia Geforce GT 630M) the issue remains.

The scirpt is attached to an empty game object (with only transform component). Code is very simple:

 public class PolygonTester : MonoBehaviour {
     private Mesh terrainMesh;
       
     private void Start()
     {
         Vector3[] vertices = new Vector3[] { new Vector3(0, 0, 0), new Vector3(10, 0, 0), new Vector3(10, 10, 0), new Vector3(0, 10, 0) };
         Vector2[] uv = new Vector2[] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1), new Vector2(1, 1) };
         int[] triangles = new int[] { 0, 1, 2 ,2,3,0};
 
         terrainMesh = new Mesh();
         terrainMesh.SetVertices(new List<Vector3>(vertices));
         terrainMesh.SetUVs(0,new List<Vector2>(uv));
         terrainMesh.SetTriangles(triangles,0,true);
         terrainMesh.RecalculateBounds();
         terrainMesh.RecalculateNormals();
 
         gameObject.AddComponent<MeshRenderer>();
         gameObject.AddComponent<MeshFilter>().mesh = terrainMesh;
         
         MeshRenderer rnd = GetComponent<MeshRenderer>();
         
         rnd.sortingLayerID = 0; 
         rnd.sortingOrder = 100;
     }
 }

Could someone point me what else can I check?

Thnx

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by norther · Jan 02, 2017 at 10:30 PM

I found a solution for this issue. I seems that the problem occurs only when I create an Empty object for the mesh. When I created a Cube object (3D Object->Cube) instead it is working. Maybe the emty object in a 2d game is derived from another class then 3d object and is not capable of rendering meshes.

The Cube has MeshRenderer and MeshFilter components so I needed to adjust the code to load them instead of creating them in order to replace the mesh and set sorting layer.

Comment
Add comment · Show 1 · 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 homer_3 · May 31, 2020 at 08:29 PM 0
Share

I had a similar issue and it was because I didn't add a mesh renderer to the empty object.

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

94 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

Related Questions

How to combine meshes for trees 0 Answers

Why is my mesh not showing outside of an area? 0 Answers

Failed Getting triangles & Failed setting Triangles - Using Quixel Voxel Terrain 0 Answers

I can see the outline of my objects but there invisible? 2 Answers

Best way to display a 2D shape from x,y positions 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