Search Unity

Animated Custom Properties on Playables streams

Discussion in 'Animation' started by quijijibo, Aug 25, 2020.

  1. quijijibo

    quijijibo

    Joined:
    Oct 31, 2012
    Posts:
    3
    Hey all

    I've been working with Playable graphs recently and can't seem to find a way to bind Animated Custom Properties to a Playables stream.

    With Mecanim it's somewhat of a hidden trick that adding parameters with the same name onto your controller will then bind and animate the values. This does not appear to work with an AnimatorControllerPlayable running a controller with named parameters.

    To bind them on stream I'm using BindCustomStreamProperty and passing the same parameter names. Should that be sufficient? Or, is there another method I'm missing? The docs are slim on this info.

    - I can manually copy the data every frame from Animator.GetFloat into the Job Data but that is terribly slow
    - I tried AnimationPlayableExtensions.SetAnimatedProperties from my base clip as well with no luck

    Thanks!
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    animator.BindStreamProperty(animator.transform, typeof(Animator), propertyName)

    That's how I do it in Animancer.
     
  3. quijijibo

    quijijibo

    Joined:
    Oct 31, 2012
    Posts:
    3
    Hey, thanks a lot - that solved it!

    What is the logic you follow for binding stream properties like this? It doesn't make a lot of sense to me and very difficult to debug in the black box.

    Say you wanted to animate a blend shape on a skinned mesh renderer on a stream as well, I would assume something like:

    animator.BindStreamProperty(skinnedMeshRenderer.transform, typeof(SkinnedMeshRenderer), name) or typeof(Mesh) But, neither properly affect the blend shape weights with SetFloat calls.

    How do we know where and what type the component property is stored on? Even with the CsReference source code from Github it isn't obvious :(

    Maybe I should checkout Animancer if it wraps up this interface in a more logical way?
    Thanks!
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I definitely recommend Animancer. It's far easier to use than the raw Playables API and has far better documentation.

    typeof(SkinnedMeshRenderer) should be right since that's where blend shapes are, so maybe the name is the problem. Animancer has an Animation Type system which shows a warning in the Inspector if an animation is trying to control a property that doesn't exist on the character, so you could play the animation on an empty Animator and then click the warning to find out what all its properties are called and look for the blend shapes. Or if you want to do it in code, one of the methods in UnityEditor.AnimationUtility takes a clip and returns an array of all its bindings so you could just log all their names.
     
  5. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    52
    Hello, need help. I have few animation clips with animated custom property that are played in Timeline track. How can i get this value from them? tried to use animator.BindStreamProperty(animator.transform, typeof(Animator), propertyName), but with no luck (maybe doing it wrong)
     
  6. quijijibo

    quijijibo

    Joined:
    Oct 31, 2012
    Posts:
    3
    The advice from Kybernetik above (and a bug he pointed out in another thread) is what helped me with my binding issues. Thanks x2 Kybernetik!

    AnimationUtility.GetAnimatableBindings gives you an array of EditorCurveBinding[]. Looking at the .propertyName on those bindings can give you insight into how to properly specify the propertyName field for BindStreamProperty on your animator.Ø

    In my case I was also facing the issue in Unity that only the source playable in a playables graph will have access to the custom property bindings. I had an AnimatorControllerPlayable as the source playable with inputs coming from an AnimationScriptPlayable and expected to get the binding values in it. Reworking the graph so that the script playable is the source and receives input from the controller playable allowed me to access the properties in the script playable correctly.

    Hope that helps

    Q
     
  7. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    52
    Big thanks for help, just starting with playbles and animation jobs to do this. Can you outline the direction how to organize it (have problems to wrap my head around it and where to start)?
    Should i follow something like this?
    https://docs.unity3d.com/ScriptReference/Animations.PropertyStreamHandle.html