Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Question Animation Randomizer with clips shared across all characters

Discussion in 'Computer Vision' started by NPSimulation, Dec 3, 2021.

  1. NPSimulation

    NPSimulation

    Joined:
    Oct 6, 2020
    Posts:
    7
    Hi everyone,

    I'm working with 100+ different characters that I want to animate and annotate. I also have more than 30 different animations that are compatible with each character.

    At the moment I can do that by assigning animations to the exposed "AnimationClips" parameter of the AnimationRandomizerTag class for each character and make the assignment automatic.

    But what I would rather do is create a few "AnimationClipParameters" and assign them a list of animations.
    This would:
    - Ensure that all my characters always have the exact same list of animations
    - Avoid having 100+ characters, each with their own list of animations despite them being the same for everyone
    - Allow me to create different thematic lists such as "dancing anims", "standing anims" "anims with props" ... that I could easily enable and disable depending on the needs

    So I tried to do that by creating a MonoBehaviour class with a "AnimationClipParameter" parameter but I'm confused by the extra properties that become visible in the inspector and that were hidden when declared in the class "AnimationRandomizer" (since this class inherits from "Randomizer" and is drawn with a custom editor when attached to the scenario).

    I would have thought that having set 5 animation clips in "Categories" I could set the probability for each animation to be sampled by setting a value between 0 and 1 in "Probabilities" but this results in a NullRef error.

    Does anyone know how to produce the desired effect or how these properties work?

    Thank you very much :)

    UniformDistribution.PNG NonUniformDistribution.PNG
     
  2. JamesB

    JamesB

    Unity Technologies

    Joined:
    Feb 21, 2012
    Posts:
    133
    Hello there. I'm afraid I'm not 100% sure on what you're asking and I'm not familiar with the AnimationRandomizerTag or Randomizer classes. Nevertheless I shall do my best to answer! It sounds like you want to group animation clips together by theme and then have characters play from that list of animations randomly - possibly selecting the list they play from randomly as well. Given that I'm not sure if this exactly what you're asking I'll try and give you the information to solve the problem yourself rather than answer it directly.

    This sort of thing will be quite difficult to achieve with a standard AnimatorController. What's more, if you want to adjust things then that will be awkward. It is possible to create and modify AnimatorControllers through scripting such as in the example here: https://docs.unity3d.com/ScriptReference/Animations.AnimatorController.html

    However, I believe even this will still not be enough to get the fine grained control you seem to be looking for. Fear not! There is a solution! Under the hood, AnimatorControllers are PlayableGraphs. These control the mixing and playing of animations that have been assigned to the AnimatorController. You can make your own PlayableGraphs. Since you have complete control over what goes into a PlayableGraph when you make it yourself you can design your data set to match what you need.

    For example, create a serializable class which contains a collection of AnimationClips. A MonoBehaviour then has a collection of these classes and controls the random selection of them for creating PlayableGraphs at runtime. Information of PlayableGraphs and the sort of scripting APIs you'll need can be found here:
    https://docs.unity3d.com/ScriptReference/Playables.PlayableGraph.html
    https://docs.unity3d.com/ScriptReference/Animations.AnimationMixerPlayable.html
    https://docs.unity3d.com/ScriptReference/Animations.AnimationClipPlayable.html

    I hope something there helps.
     
    RuiyuZhang_Unity likes this.