c# - Unity Game Engine Crashing When Trying To Update The Vertex Positions Of A Mesh In Real Time Using A Script -


so in unity i’ve created script generates plane mesh made of triangles. plane has 400 vertices (20x20 grid) 361 squares made of 2 triangles comprising 3 vertices each (2166 indices). mentioned vertices, indices , normals set in start() function vertices being loaded vector3 array called vertices, indices being loaded array of single floats , normals being loaded array of vector3. these assigned mesh (representing plane) int start() function so:

    mesh.vertices = vertices;     mesh.triangles = triangles;     mesh.normals = normals; 

in update() function function called calculates new positions every single vertex in plane mesh (400):

void update ()  {     updatemesh ();     mesh.vertices = vertices; } 

with updatemesh function looking this:

void updatemesh()                                                                        {                                                                                                //this function update position of each vertex in mesh      (float = 0f; i<1f; i=+0.05f) {         (float j = 0f; j<1f; j+=0.05f) {             pos = (int)((i * 20) + (j*20));             vertices[pos] = updatept(j, i);          }     } } 

once new vertices have been updated, indices , normals remain same newly calculated vertex positions must loaded onto mesh object. , attempted in update() function can seen above.

however play button pressed in unity, engine crashes , i’m not sure why – possible recalculation function not finishing cycle before unity renders? (i have reduced number of vertices in mesh because same problem occurring when mesh had 10000 vertices (100x100 grid)). or because not doing in update() function?

i think might typo @ line

for (float = 0f; i<1f; i=+0.05f) { 

it should read += not =+ .

it getting stuck in infinite loop because never incremented.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -