Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

The madness of SkinnedMeshRenderers and SharedMeshes/materials

Discussion in 'Animation' started by Ne0mega, May 6, 2022.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    558
    So, Trying to create a new skinned mesh renderer, so it can use the same settings as imported, but with say different vertex colors or vertex placements has been very frustrating to say the least. I got it done, but it requires a whole bunch of workarounds.

    I thought this must be because of performance, shared meshes more performant than a bunch of individual mehses with different vertices, normals, colors, etc.

    Turns out, that is not the case, at least not for me, as I eventually was able to get new instances of skinnedMeshRenderers with changed meshes and vertex colors, and saw zero performance difference.

    What I don't get is why instead of this:

    Code (csharp):
    1.  
    2.             Mesh mesh0 = SMR0.sharedMesh;
    3.             Mesh meshInstance0 = Instantiate(mesh0);
    4.             meshInstance0.colors = vertexColorStream;
    5.             meshInstance0.vertices = verts;
    6.             SMR0.sharedMesh = meshInstance0;
    7.             SMR = SMR0;
    8.  
    can't it be as simple as this:

    Code (csharp):
    1.  
    2. SkinnedMeshRenderer SMR = new SkinnedMeshRenderer(OriginalSMR);
    3.  
    or
    Code (csharp):
    1.  
    2. SkinnedMeshRenderer SMR = Instantiate(OriginalSMR);
    3.  
    like just about every other component?
    Why must everything on a skinnedMeshRenderer be shared and almost inaccessible to a new instance of it?
     
unityunity