HELP! new guy in trouble!

So I have been playing with Unity for a couple of weeks, just concentrating on how to build scenes at present and not really looked at coding yet. Was using it the other day, no problems, just logged on and now play mode won’t run due to errors, but I have not idea where to begin fixing these errors.

I have attached a screen shot the errors and a txt file of the code.

Please help!


2801201–203323–script.txt (5.23 KB)

The errors all appear to be in this section of code:

public static Mesh Combine (MeshInstance[ ] combines, bool generateStrips)
{
int vertexCount = 0;
int triangleCount = 0;
int stripCount = 0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
{
vertexCount += combine.mesh.vertexCount;

if (generateStrips)
{
//SUBOPTIMAL FOR; PERFORMANCE;
//int curStripCount = combine.mesh.GetTriangleStrip(combine.subMeshIndex).Length;
//if (curStripCount != 0)
{
if( stripCount != 0 )
{
if ((stripCount & 1) == 1 )
stripCount += 3;
else
stripCount += 2;
}
stripCount += curStripCount;
}
//else
{
generateStrips = false;
}
}
}
}

// Precomputed how many triangles we need instead
if (!generateStrips)
{
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
{
triangleCount += combine.mesh.GetTriangles(combine.subMeshIndex).Length;
}
}
}

Vector3[ ] vertices = new Vector3[vertexCount] ;
Vector3[ ] normals = new Vector3[vertexCount] ;
Vector4[ ] tangents = new Vector4[vertexCount] ;
Vector2[ ] uv = new Vector2[vertexCount];
Vector2[ ] uv1 = new Vector2[vertexCount];
int[ ] triangles = new int[triangleCount];
int[ ] strip = new int[stripCount];

int offset;

offset=0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
Copy(combine.mesh.vertexCount, combine.mesh.vertices, vertices, ref offset, combine.transform);
}

offset=0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
{
Matrix4x4 invTranspose = combine.transform;
invTranspose = invTranspose.inverse.transpose;
CopyNormal(combine.mesh.vertexCount, combine.mesh.normals, normals, ref offset, invTranspose);
}

}
offset=0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
{
Matrix4x4 invTranspose = combine.transform;
invTranspose = invTranspose.inverse.transpose;
CopyTangents(combine.mesh.vertexCount, combine.mesh.tangents, tangents, ref offset, invTranspose);
}

}
offset=0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
Copy(combine.mesh.vertexCount, combine.mesh.uv, uv, ref offset);
}

offset=0;
foreach( MeshInstance combine in combines )
{
if (combine.mesh)
Copy(combine.mesh.vertexCount, combine.mesh.uv2, uv1, ref offset);
}

int triangleOffset=0;
int stripOffset=0;
int vertexOffset=0;
//foreach( MeshInstance combine in combines )
{
if (combine.mesh)
{
if (generateStrips)
{
int[ ] inputstrip = combine.mesh.GetTriangleStrip(combine.subMeshIndex);
if (stripOffset != 0)
{
if ((stripOffset & 1) == 1)
{
strip[stripOffset+0] = strip[stripOffset-1];
strip[stripOffset+1] = inputstrip[0] + vertexOffset;
strip[stripOffset+2] = inputstrip[0] + vertexOffset;
stripOffset+=3;
}
else
{
strip[stripOffset+0] = strip[stripOffset-1];
strip[stripOffset+1] = inputstrip[0] + vertexOffset;
stripOffset+=2;
}
}

for (int i=0;i<inputstrip.Length;i++)
{
strip[i+stripOffset] = inputstrip + vertexOffset;
}
stripOffset += inputstrip.Length;
}
else
{
int[ ] inputtriangles = combine.mesh.GetTriangles(combine.subMeshIndex);
for (int i=0;i<inputtriangles.Length;i++)
{
triangles[i+triangleOffset] = inputtriangles + vertexOffset;
}
triangleOffset += inputtriangles.Length;
}

vertexOffset += combine.mesh.vertexCount;
}
}

Mesh mesh = new Mesh();
mesh.name = “Combined Mesh”;
mesh.vertices = vertices;
mesh.normals = normals;
mesh.uv = uv;
mesh.uv2 = uv1;
mesh.tangents = tangents;
if (generateStrips)
mesh.SetTriangleStrip(strip, 0);
else
mesh.triangles = triangles;

return mesh;
}

Looks like its quite old script, so things have changed… maybe this helps:

Yeah, you’ve commented out the lines that declare the variables which, by line 37, you’re attempting to use.

If you’re just “concentrating on how to build scenes at present and not really looked at coding yet” then you shouldn’t be using this script. It’s advanced stuff, and using a script you can’t understand is never a great idea. Throw it out, and throw out whatever’s in your scene (if anything) that is using it, and focus (as you say) on learning to build scenes.

1 Like

Thanks, Joe,
Using the code was certainly not intentional, I believe it must have come along with something I brought in from the asset store.
Can I simply delete the whole block of the script? How would I know if something in the game is using it?

Delete the script itself. (If you don’t know where it is, click in the little search field in the Project tab, and type a bit of its name.)

If anything is using it, you’ll know because you’ll get new errors.

If really in doubt, just create a new project! Then you’ll be good for sure. :slight_smile:

2 Likes

thanks, don’t think I really want to start a new project, built a pretty comprehensive map. I’ll try deleting it. :confused:

cool, that worked! Script deleted with no disastrous side effects. Thanks Joe!

1 Like