Cannot convert from 'System.Collection.Generic.List<int>' to 'int[]'

I’ve been having this error and keep on failing to fix it, could anyone help me?

Here’s the code of the function the error is happening in:

void GenerateMesh()
    {
        Mesh newMesh = new Mesh();
        List<Vector3> vertices = new List<Vector3>();
        List<Vector3> normals = new List<Vector3>();
        List<Vector2> uvs = new List<Vector2>();
        List<int> indices = new List<int>();

        int currentIndex = 0;
        for (int x = 0; x < Size; x++)
        {
            for (int y = 0; y < Size; y++)
            {
                for (int z = 0; z < Size; z++)
                {
                    Vector3Int offset = new Vector3Int(x, y, z);
                    if (BlockIDs[x, y, z] == 0) continue;
                    else
                    {
                        GenerateBlock_Top(ref currentIndex, offset, vertices, normals, uvs, indices, new Rect());
                    }
                }
            }
        }
        newMesh.SetVertices(vertices);
        newMesh.SetNormals(normals);
        newMesh.SetUVs(0, uvs);
        newMesh.SetIndices(indices, MeshTopology.Triangles, 0);

        newMesh.RecalculateTangents();
        MeshFilter.mesh = newMesh;
        MeshCollider.sharedMesh = newMesh;
        // Set Texure (No texture Yet!)

        RequiresMeshGeneration = false;
    }

Thanks alot.

Which line gives the error?

Anyway, you can convert your list to array using .ToArray() in Linq

Well, since SetIndices can take a List of integers, the only place where this error may arise is your “GenerateBlock_Top” method which probably expects an int array instead of a list. This is most likely an older piece of code from a time where we didn’t have the SetIndices methods and the indices always was an array.

That method also has “currentIndex” as ref parameter, most likely to keep track where you are inside the indices array. When you use a List, all this would not be necessary. So your issue is the signature / innerworkings of your “GenerateBlock_Top” method. You may follow some old / outdated tutorial?

It gives the error on line 78
newMesh.SetIndices(indices, MeshTopology.Triangles, 0);

Also .ToArray() Gives me a diffrent error: Cannot implicitly conver type ‘int[ ]’ to ‘int’

Well, that’s not really possible if your newMesh is a UnityEngine.Mesh instance. Here’s a screenshot

So something has to be different on your side. Either your error is not in that file and that line, or something else has to be off. We can not reproduce the issue.

btw: What Unity version do you use?