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.
  2. Dismiss Notice

Question OnValidate() not working with animation

Discussion in 'Animation' started by tanmaykulkarni, Jan 24, 2023.

  1. tanmaykulkarni

    tanmaykulkarni

    Joined:
    Nov 5, 2019
    Posts:
    104
    Hey Devs,
    I have a script to control multiple blend shapes of skin mesh renderers. The script has floats and an OnValidate() void. Whenever the float changes, the blend shape weight should change. This works normally in real-time, however, when an animator controls the floats of that script, the blend shape weights are no longer changing.
    Code (CSharp):
    1. public float B1Value;
    2. public SkinnedMeshRenderer smr;
    3.  
    4. void OnValidate()
    5. {
    6.      smr.SetBlendShapeWeight(1, B1Value);
    7. }
    What should I do to make OnValidate() work in animations and change blend shapes?
     
    yusufyldz318 likes this.
  2. tanmaykulkarni

    tanmaykulkarni

    Joined:
    Nov 5, 2019
    Posts:
    104
    Anyone from Unity Technologies?
     
  3. yusufyldz318

    yusufyldz318

    Joined:
    Jun 20, 2022
    Posts:
    15
    Unfortunately it's not possible to use OnValidate on runtime because it is editor only function. You can define a float in the animator and access it by using "animator.GetFloat()" in the Update. That way whenever you change the variable in the animator by some animation, it will be updated directly.