Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Problem with inconsistent skinning

Discussion in 'Animation' started by EduAlvarado, Mar 3, 2021.

  1. EduAlvarado

    EduAlvarado

    Joined:
    May 11, 2020
    Posts:
    6
    Hello everyone,

    Given two identical skeletons (A and B, being A is already skinned), I am trying to instantiate a copy of the mesh skinned with skeleton A, and skinned to skeleton B. Both skeleton hierarchies are the same, but are animated differently.

    It skins properly. However, when the character moves at high speeds (e.g. rotates fast), there are the following artifacts. It's like the skinned bones do not rotate and connect well.



    This is the method that I wrote to skin the skeleton:

    Code (CSharp):
    1.  
    2.  
    3. // The skin I want to copy from
    4. public SkinnedMeshRenderer skinnedMeshRendererSurfaceA;
    5.  
    6. //  Root of skeleton A
    7. public Transform skeletonA;
    8.  
    9. // I use this for other purpose explained later
    10. public List<Transform> bonesCorrectOrder;
    11. public Transform variableArmature;
    12.  
    13. private void SkinningSkeleton()
    14.     {
    15.         // Create an instance of SkinnedMeshRenderer (B)
    16.         SkinnedMeshRenderer skinnedMeshRendererSurfaceB;
    17.  
    18.         // Make the copy of A
    19.         skinnedMeshRendererSurfaceB= Instantiate(skinnedMeshRendererSurfaceA, this.transform);
    20.  
    21.         // Only make visible B
    22.         skinnedMeshRendererSurfaceA.enabled = false;
    23.         skinnedMeshRendererSurfaceB.enabled = true;
    24.  
    25.         // I can't attach directly the list of bones from the hierarchy to skinnedMeshRendererSurfaceB.bones, since they had different order. Therefore, I need to rearrange the bones from the hierarchy following the order of skinnedMeshRendererSurfaceA.bones.
    26.         foreach (Transform tfm in skinnedMeshRendererSurfaceA.bones)
    27.         {
    28.             bonesCorrectOrder.Add(TransformDeepChildExtension.FindDeepChild(skeletonA, tfm.name));
    29.         }
    30.      
    31.         // Assign new root
    32.         skinnedMeshRendererSurfaceB.rootBone = variableArmature.GetChild(0).transform;
    33.  
    34.         // Assign array of bones
    35.         skinnedMeshRendererSurfaceB.bones = bonesCorrectOrder.ToArray();
    36.  
    37.         // Assign material
    38.         skinnedMeshRendererSurfaceB.material = skeletonMaterial;
    39.     }
    Should I perform other operation to skin the skeleton properly? Or do you have any hint why these artifacts are happening?

    Thank you!
     
  2. EduAlvarado

    EduAlvarado

    Joined:
    May 11, 2020
    Posts:
    6
    Hello,

    Does anyone know what it could be happening? I did not found a solution yet.

    Thank you!
     
unityunity