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 Andre 1 · Mar 12, 2011 at 06:58 AM · meshcreatemeshfiltertriangle

Unity won't show my programatically created Mesh(A Simple Triangle)

Hi, my question is simple. I'm trying to create a triangle. But it does not appear to the camera. What's missing? What am I doing wrong? I tried to create a .obj with the same vertices and it worked, why my mesh does not appear?

Here's the code:

GameObject.FindWithTag("Player").AddComponent();

Vector3[] verts = new Vector3[4]; Vector3[] normals = new Vector3[4]; Vector2[] uv = new Vector2[4]; int[] tri = new int[6];

     //MeshFilter mf  = GetComponent(MeshFilter);

     verts[2] = new Vector3(0, 0, 0);
     verts[1] = new Vector3(100, 0, 0);
     verts[0] = new Vector3(0, 0, 100);
     verts[3] = new Vector3(100, 0, 100);

     for (int i = 0; i < normals.Length; i++) {
         normals[i] = Vector3.up;
     }

     uv[0] = new Vector2(0, 0);
     uv[1] = new Vector2(1, 0);
     uv[2] = new Vector2(0, 1);
     uv[3] = new Vector2(1, 1);

     tri[0] = 0;
     tri[1] = 2;
     tri[2] = 3;

     tri[3] = 0;
     tri[4] = 3;
     tri[5] = 1;

     Mesh mesh = new Mesh();
     mesh.vertices = verts;
     mesh.triangles = tri;
     mesh.uv = uv;
     mesh.normals = normals;

     Color[] color = new Color[4];
     color[2] = new Color(1, 0, 0);
     color[1] = new Color(0, 1, 0);
     color[0] = new Color(0, 0, 1);
     color[3] = new Color(0, 1, 0);

     mesh.colors = color;

 GameObject.FindWithTag("Player").GetComponent<MeshFilter>().mesh = mesh;

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Andre 1 · Mar 12, 2011 at 07:02 AM

Oh, I found out, I missed adding the meshrenderer...

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 Madrayken · Dec 12, 2012 at 01:01 PM 0
Share

It would have been really helpful if you'd shown exactly what you did to fix it, too! As it is, we've got the non-working code, and only part of the knowledge that you've found a solution.

avatar image
0

Answer by Madrayken · Dec 12, 2012 at 01:59 PM

To clarify:

If this code is added to a script's 'Start' method, which is then attached to a blank gameObject, you'll have to add both a MeshFilter and MeshRenderer component to the gameObject in order for the code to display anything. A pure, blank, empty game-object won't display any results at all.

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

1 Person is following this question.

avatar image

Related Questions

Mesh Filter 8 Answers

Generated Mesh is partially rendered, but shown correctly in scene view 1 Answer

How to break up one mesh into submeshes by connected vertices? 1 Answer

Mesh and material disappear after CreatePrefab() in C# 1 Answer

creating a mesh from script 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