Search Unity

Apply blend shape same frame

Discussion in 'Animation' started by Baste, Jun 26, 2019.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    I'm running into something I believe is a bug with blend shapes, but I'm not sure.

    If I do this:

    Code (csharp):
    1. var model = Instantiate(prefab);
    2. model.skinnedMeshRenderer.SetBlendShapeWeight(index, value);
    That blend shape weight won't be applied until the next frame, meaning that the skinned mesh renderer is visible for a single frame with the wrong weight.

    If I do this:
    Code (csharp):
    1. var model = Instantiate(prefab);
    2. model.skinnedMeshRenderer.SetBlendShapeWeight(index, value);
    3. model.skinnedMeshRenderer.enabled = false;
    4. yield return null;
    5. model.skinnedMeshRenderer.enabled = true;
    I still get the same effect, just one frame delayed. In fact:

    Code (csharp):
    1. var model = Instantiate(prefab);
    2. model.skinnedMeshRenderer.SetBlendShapeWeight(index, value);
    3. model.skinnedMeshRenderer.enabled = false;
    4. yield return null;
    5. model.skinnedMeshRenderer.enabled = true;
    6. yield return null;
    7. model.skinnedMeshRenderer.enabled = false;
    8. yield return null;
    9. model.skinnedMeshRenderer.enabled = true;
    10. yield return null;
    11. model.skinnedMeshRenderer.enabled = false;
    12. yield return null;
    13. model.skinnedMeshRenderer.enabled = true;
    14. yield return null;
    15. yield return null;
    16. // This is the first point where the blend shape weight will be visible
    Two questions:
    Is this a bug?
    Is it possible to force blend shapes to apply somehow?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Definitely sounds like a bug.

    Try yield return new WaitForEndOfFrame. No idea if it will help, but it gives a slightly different time to null.

    I guess you could also try destroying the renderer and creating a new one, but that's a S***ty hack at best.
     
  3. polyflow3d

    polyflow3d

    Joined:
    Oct 6, 2014
    Posts:
    297
    The SkinnedMeshRenderer is closely related to the GPU , so it seems that their work is not synchronized with the scripts.
    You can try to use SkindMeshRender. BakeMesh () then apply resulting mesh to MeshFilter. It will be dramaticly slow but will performed in same frame that called.
     
    Baste likes this.