• 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 giulio-pierucci · Feb 13, 2015 at 09:49 PM · meshproceduralvertextriangles

Procedural mesh creation issue

Hi all!

I'm trying to do a script that creates a mesh from scratch. I follow Unity Reference Example 1:

http://docs.unity3d.com/ScriptReference/Mesh.html

I try to do a quad: 4 Vertices, 4 Normals, 4 colors, 4 uv (primary), 4 uv (secondary), 6 triangles

All are drawn correctly. But if I want add tangents (4) i get this strange error: "Mesh.tangents is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array."

I checked with debug that vertices are 4 and tangent too.

What's wrong? Is a strange bug of mi Unity version?

Thanks in advance

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 giulio-pierucci · Feb 14, 2015 at 12:18 AM

I'm very sorry. It's my fault. For explain better, I write a stupid example to post, with my big surprise, works like a charm. I'm pretty sure that the problem is elsewhere.

then, by way for apologies, i post the stupid script:

 using UnityEngine;
 using System.Collections;
 using System.Linq;
 
 public class ProceduralQuad : MonoBehaviour {
 
     [SerializeField] Material material;
 
     Mesh mesh;
     Color32 c = Color.red;
     Vector4 t = new Vector4(1, 0, 0, -1);
 
     void Start () { mesh = new Mesh(); }
     
     void Update () {
 
         mesh.Clear();
         mesh.vertices = new Vector3[] 
         {
             transform.right * -.5f + transform.up * -.5f,
             transform.right * -.5f + transform.up * .5f,
             transform.right *  .5f + transform.up * .5f,
             transform.right *  .5f + transform.up * -.5f
         };
         mesh.uv = new Vector2[] 
         {
             new Vector2 (0,0),
             new Vector2 (0,1),
             new Vector2 (1,1),
             new Vector2 (1,0)
         };
         mesh.uv2 = mesh.uv1;
         mesh.colors32 = Enumerable.Repeat(c, mesh.vertexCount).ToArray();
         mesh.triangles = new int[] { 0, 1, 2, 2, 3, 0 } ;
         mesh.normals = Enumerable.Repeat(-Vector3.forward, mesh.vertexCount).ToArray();
         mesh.tangents = Enumerable.Repeat(t, mesh.vertexCount).ToArray();
         mesh.RecalculateBounds();
 
         Graphics.DrawMesh(mesh, transform.position, transform.rotation, material, gameObject.layer);
     
     }
 }
 

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 on June 13. 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

19 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

Related Questions

Optimized vertex manipulation 1 Answer

Triangulating a 2D polygon with only hull vertices. 1 Answer

Highmap on a cube. 0 Answers

Determining where a mesh triangle faces 1 Answer

Vertex count on a procedurally generated map and some related doubts 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