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 Pauls · Mar 24, 2013 at 08:21 AM · verticesbuiltin array

Mesh.vertices is too small?

Hi,

I would like to use @Bunny83's script "custom line renderer", but because I remove the last vertices after one second, and "mesh.vertices" is a built-in array with a specific size, it says :

Mesh.vertices is too small. The supplied vertex array has less vertices than are referenced by the triangles array. UnityEngine.Mesh:set_vertices(Vector3[])

Is there a way to avoid this error? I have tried to replace the built-in array with a List, but Unity does not allow it. Would you have any idea?

Here is the link : http://answers.unity3d.com/questions/64716/can-i-render-nice-thick-lines-with-linerenderer-wi.html

Thanks


EDIT :

My function in another script is like that :

     void Update () {
                 
         if(myPoints != null){
             lineRenderer.SetVertexCount(myPoints.Count);
             for(int i = 0;i<myPoints.Count;i++){
                 lineRenderer.SetPosition(i,myPoints[i]);    
             }
         }
         else
         lineRenderer.SetVertexCount(0);
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

3 Replies

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

Answer by Fattie · Mar 24, 2013 at 10:47 AM

in a word ...

say a model has 100 triangles.

this means it will have 300 vertices.

[aside .... see note on "shared vertices" below]

recall that any TRIANGLES array simply has three entries for each triangle

so your TRIANGLES array will have 300 entries, and your vertices array will have 300 entries

say you want to take away 11 triangles

now, your TRIANGLES array now has 89 triangles, and is hence 267 length.

you now have 267 vertices so you'll need an all-new vertices array with 267 vertices.

note that the TRIANGLES arrray is the key thing you have to change, if you want to get rid of some triangles.

you "just have to" change the VERTICES each time you change the triangles for any reason.

however, don't forget that sometimes, you share vertices in thevertices array.

it's critical to understand that you do not have to share vertices, but you can if you want

So you might have two triangles (six verts). the TRIANGLE array would be and must be length six because you have six verts (two tris).

however, imagine you are sharing two of the vertices (draw a diagram)

so, if you wanted to do that, your verts array would be only four long.

again note that you DO NOT HAVE TO, for any reason, share vertices

this is a common misconception .. here is an ancient argument about it

http://answers.unity3d.com/questions/193695/in-unity-is-there-a-fast-way-to-find-nearby-triang.html

actually, it is much easier, when you are starting out, to not share vertices

quite simply: your verts array will always be the same length as your triangles array

So in a word .. it's the TRIANGLES array, you want to change, in this situation.

Hope it helps.

there are many discussions on these issues here

http://answers.unity3d.com/questions/329116/do-we-need-to-call-recalculatenormals-if-normal-ve.html

http://answers.unity3d.com/questions/352513/ways-of-modificating-mesh-triangles.html

BTW it's important to remember that when you access .vertices it CREATES A WHOLE COPY, it's a real gotchya in Unity when you're getting started. Cheers

Comment
Add comment · Show 2 · 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 Pauls · Mar 24, 2013 at 11:39 AM 0
Share

Thanks Fattie, sorry I am a bit lost, in SetVertexCount, there is this line : m_Indices = new int[m_Points.Count*2]; and it is used in Update$$anonymous$$esh to create the triangle strips : m_$$anonymous$$esh.SetTriangleStrip(m_Indices,0); . Should I add something like that in SetVertexCount : m_$$anonymous$$esh.triangles = new int[m_Points.Count*2]; ? This triggers an error : "Null Reference". Could you help me with this? I have also edited my post to add the code I am using in the Update function. Thanks

avatar image Fattie · Mar 24, 2013 at 11:50 AM 0
Share

I'm afraid I don't understand the specific code at all, sorry - but i'm sure someone else will help.

(I am too young to know about "vertex strips", that is more of a previous-generation idea.)

Essentially, if you get this error:

$$anonymous$$esh.vertices is too small...

your problem is you must set the .triangles array

the ,vertices array is merely an assistant to the .triangles array. you must understand, work with, and change the .triangles array. As a secondary issue, you would change the .vertices array.

read here for a number of basic examples

http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$esh.html

hope it helps in some way until someone else helps specifically!

avatar image
20

Answer by col000r · Feb 03, 2016 at 08:06 AM

The problem is that while it's okay to update the position of vertices, Unity doesn't react well to you changing the number of vertices, because it immediately checks it against the triangles and complains. Even though you were probably about to assign new triangles as well, it's too late - the Error is already there.

The trick is to do mesh.Clear(), and then set everything anew: vertices, triangles and whatever else you assigned.

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 Map-Builder · Feb 21, 2017 at 12:42 AM 0
Share

This is it thanks

avatar image
4

Answer by Steven-Walker · Feb 11, 2014 at 01:04 AM

I ran into this error with a custom editor script that generates geometry dynamically. Even though my vertex and triangle counts were correct, the error was still occurring intermittently. The solution was to create a new Mesh every time when regenerating the polygons, rather than trying to modify an existing mesh. Also be sure to set the vertices before triangles.

Comment
Add comment · Show 3 · 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 frogsbo · Mar 10, 2014 at 07:30 PM 3
Share

great answer

solved by using prior to renewing: extruded$$anonymous$$esh.Clear();

avatar image magic9cube · Jun 20, 2014 at 11:21 AM 0
Share

This fixed it for me too.. cheers!

avatar image Ignorant · Mar 27, 2015 at 05:55 AM 0
Share

I just ran into this. Quite surprising since docs are saying: "set vertices before triangles" but you can't set them earlier, because it's invalid :) Will do as Steven Walker suggested - recreate a mesh. However Unity docs should mention it.

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

14 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

Related Questions

why is Unity got more vertices than 3dsmax 1 Answer

Small Vert/Tris count still generating more draw calls than expected 1 Answer

How to add vertices to a cube 1 Answer

Ways of modificating mesh triangles 3 Answers

A doubt in QA on performance on a generic mesh info? 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