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

Animancer - Less Animator Controller, More Animator Control

Discussion in 'Assets and Asset Store' started by Kybernetik, Oct 8, 2018.

  1. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    The Playables API only grabs the Animator's Update Mode when it initializes and doesn't support changing to or from Animate Physics mode after that so it's generally recommended to set the mode you want before playing any animations so Animancer can just start in the right mode. Otherwise, for Unscaled Time it's fine to just set it on the Animancer Component.
     
  2. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,771
    Hi @Kybernetik,
    Just wondering, is there a way to update Animancer on twos?
    Thanks!
    Pete
     
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    I'm not really sure what you're asking.

    If you want to manually update Animancer, the Update Rate Example demonstrates how you can do that.
     
  4. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,771
    Yeah that sounds perfect!
    Basically it’s just updating the animation every second frame. Something animators used to do to save time drawing I think but I wanted to get that look.

    Thanks!
     
  5. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,681
    EDIT SOLVE:!

    So, the issue was simply that I had edited some of the transform (as bones in the rig's) names. I do get why this would cause issue. Anyhow DONT CHANGE ANY NAMES!!




    Hi @Kybernetik,

    Now I know this question is 99.999% zero to do with Animancer, but I am hoping you may have some key insights.

    I have done AB tests, with one working and one not. But let's say in this state I have an animation running, but not affecting the skinned mesh renderer.

    What would YOU do under this case?

    Thank you in advance for any insight.
     
    Last edited: Sep 18, 2023
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,681
    @Kybernetik
    In regards to ragdoll and animations, I have run into an odd occurrence. You can see video posted below (*Note Physics Debugger is on) and I am using Unity Ragdoll Wizard to set up the ragdoll.

    I did notice on the Animancer site that it highlights using Puppet Master or Hairibar. Is this a required step or is the Unity Ragdoll Wizard fine?

    I ask this as I think at some point I would like to run a ragdoll and an animation on the same body. But at the end of the day, when running Ragdoll and Animations on the same body it gets weird when ragdoll is activated.




    So in your mind, what might be the issue?
     
    Last edited: Sep 19, 2023
  7. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Those two are the only ragdoll systems I've tested but they just work normally so any ragdoll system that can work with animations should still work with Animancer. If in doubt, try just sticking your animation in an Animator Controller and playing it without Animancer to see how it interacts with that ragdoll system.

    That hunched over pose is what you get from a Humanoid Rig when it isn't playing anything (specifically, when all the animations are at 0 weight or they aren't Humanoid animations).

    The slowly sinking could be if those are Rigidbodies which are actually falling and the ragdoll system is teleporting them back to the model every frame but their velocity is still increasing so what you're actually seeing is one frame of their velocity pulling them down.
     
  8. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    591
    Hi @Kybernetik

    I'm using animancer to transition to animations in code and was wondering what would be the best way to have a 'default' animation.

    I want to automatically return to an Idle animation after non-looped animations are played.

    Thanks
     
  9. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    If you have a central script which everything interacts with like the Character script in the Characters Example, you could put your default animation and a method to play it there so any animation can use that method in its end event.

    Another option would be to make a script which inherits from AnimancerComponent, put the default animation stuff there, and use it instead of the AnimancerComponent you would normally use.
     
    xjjon likes this.
  10. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    100
    Hi, since target matching doesn't work with Animancer, I'm currently wondering how I can implement a ledge grab mechanic. My best guess is:

    1. Perform a lot of raycasts to check if a ledge grab should be performed
    2. Switch to root motion
    3. Disable character collider
    4. Animancer.Play the ledge climb animation clip
    5. When done, activate the character collider and disable root motion

    Or is there something else to make sure my character is in the right position after the ledge climb animation?
     
  11. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    I've never implemented a ledge climb mechanic, but that sounds like it should work.

    If you want to modify it without modifying the animation you could calculate the destination using
    startPosition + clip.averageSpeed * clip.length
    and offset it by adding
    (yourDesiredDestination - calculatedDestination) * Time.deltaTime / clip.length
    to the character's position every frame.
     
    baumxyz likes this.
  12. baumxyz

    baumxyz

    Joined:
    Mar 31, 2017
    Posts:
    100
    Oh, that's a good suggestion, I will test that out. Thank you very much!
     
  13. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    506
    Hi, can I import animations into my game outside of the editor? I mean, inside the build version?"

    And does this asset support playmaker? Because I can't write codes.
     
  14. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Unfortunately, Unity doesn't allow non-legacy animations to be created at runtime and Animancer can't play legacy animations so if you want to do that you need to use the Legacy Animation system.

    I have no experience with Playmaker so I don't really know what would be required to support it. I'd be willing to work with someone familiar with Playmaker to figure out what would be needed, but so far no one has taken me up on that.
     
    Crossway likes this.
  15. aaefiikmnnnr

    aaefiikmnnnr

    Joined:
    Aug 21, 2014
    Posts:
    12
    Hello,

    I was trying to make a 2D action game with Animancer. But I encountered a strange phenomenon which I would like to ask for help. The project extract is commited here: (I was using Animancer v7.4.2 and it's removed from repo)
    https://github.com/FrankNine/AnimancerTest

    Things are fine for most cases. But if you wait and get hit by the enemy then hit space to jump, the playable character will suddenly be teleported by to where she gets hit then jump. And the issue will only happen for each play mode, after that following operations and animations seem fine. I would like to ask did you encounter this kind of behaviour before? Thank you for your help.
     
  16. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    I'm not able to load your project due to a lot of compile errors which seem to all be either:

    "The name 'Unsafe' does not exist in the current context"

    Or

    "A result of a stackalloc expression of type 'Span<byte>' cannot be used in this context because it may be exposed outside of the containing method"
     
  17. aaefiikmnnnr

    aaefiikmnnnr

    Joined:
    Aug 21, 2014
    Posts:
    12
    Hello,

    I moved some files out of LFS and updated the repository. Please pull and try again. Thank you very much.
     
  18. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Your BrawlerGirlHurt animation has position keyframes in it. I'm not sure why that only causes a problem in the situation you described, but removing them seems to fix the issue.
     
  19. aaefiikmnnnr

    aaefiikmnnnr

    Joined:
    Aug 21, 2014
    Posts:
    12
    Hello,

    I was thinking of using position keyframes and OnAnimatorMove() to control the arc of the on-hit knockback.

    I tried random stuff and found that by playing all animation once at init then stop them all would remove this issue, but it looks too unexplainable. It seems I still need to find another way to implement on-hit knockback. Thank you again for your help.

    Code (CSharp):
    1. public void Init()
    2.     {
    3.         _animancer.Play(_idleAnimationClip);
    4.  
    5.         _punchHitBox.InitializeCollider();
    6.         _diveKickHitBox.InitializeCollider();
    7.  
    8.         // Hack fix animancer teleporting character back to place before hurt
    9.         _animancer.Play(_idleAnimationClip);
    10.         _animancer.Play(_walkAnimationClip);
    11.         _animancer.Play(_attackAnimationClip);
    12.         _animancer.Play(_jumpAnimationClip);
    13.         _animancer.Play(_jumpAttackAnimationClip);
    14.         _animancer.Play(_hurtAnimationClip);
    15.         _animancer.Stop();
    16.     }
     
  20. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    That seems like a terrible hack, but I'm not sure why the issue would be happening in the first place.

    You likely only need to play the hurt animation on startup though.
     
  21. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    Hi dev, I have taken a look at the Airborne page but still don't understand how to do Jump using Mixer.
    From what I see, your Mixer set the range from -5 0 5, which 5 is the start of the jump velocity, and -5 is when we land.
    When I implement it, it looks like this at the Jump_End anim.
    upload_2023-10-8_0-5-2.png
    upload_2023-10-8_0-5-10.png
    The pose is not what I need because right now all the 3 animations are at the same normalizedTime (play at the same time) = 1.2. At 1.2 normalizedTime the pose is like idle pose.
    While what I need is the Jump_End has to start from 0, like this
    upload_2023-10-8_0-6-49.png
    and then at 0.24 : land pose.
    upload_2023-10-8_0-7-17.png

    I still don't understand Mixer much, why do all 3 animations play at the same time?
     

    Attached Files:

  22. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269

    This is the video to demonstrate, Begin Jump and Jump Loop is okay, just the Jump End is wrong.

    Jump Mixer upload_2023-10-8_0-19-13.png
     
  23. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
  24. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    Thank you, I'm so dumb, yes the landing should be outside of the mixer.
    Since playing with the mixer SO, I think why there is asset type? wouldn't it be easier to bind the character's script public method for event callback if we just use normal class type mixer.
    So my question is, in the design point of view, what is the purpose of mixer SO and transition SO?
     
  25. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Defining your transitions as assets allows you to easily share them between characters without needing to manually copy the same setup. It's also generally more efficient because every instance of a character simply references the same object in memory instead of everyone having their own copy.
     
    hopeful and Spikebor like this.
  26. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    thanks, another quick question, It seem that my mixer fade value does nothing.
    as soon as I press jump the pose snap right to this pose
    upload_2023-10-8_12-9-20.png
    despite I've set the fade in duration to be 0.2s
    upload_2023-10-8_12-9-38.png
    is this a bug?

    speciafically, how to blend with the previous walkRunSprint state?
    I notice as soon as the jump mixer start playing, its weight is set to 1, and the walkRunSprint weight is 0.
     
    Last edited: Oct 8, 2023
  27. Rusted_Games

    Rusted_Games

    Joined:
    Aug 29, 2010
    Posts:
    135
    Hi @Spikebor that's a common mistake we do, the jump state is not aware of the next desired state, I'd suggest checking the jump state end state where you should be switching to your walkrunsprint (assuming there's a idle animation there). In the examples you'll see the Character.StateMachine.ForceSetDefaultState();
     
    Kybernetik likes this.
  28. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    hi bro, good now, I don't think I have to pass in the mixer's duration parameter.
    Since I thought it is automatically used
    Play(jumpState,jumpMixer.FadeDuration);
     
  29. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    If you want it to use the transition's fade duration you need to tell it to play the transition, not the state (i.e. Play(jumpMixerTransition). If you do need to tell it to play the state directly for some reason, then specifying the fade duration as you have is likely correct.
     
    Spikebor likes this.
  30. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    I have to create state on start because
    jumpMixer.State.Parameter = vspd;
    this line will return error that the state is not created.
    So to do this I have to create state on start, then when play I'll play state / not mixer.
     
  31. heartshapedbox

    heartshapedbox

    Joined:
    May 27, 2018
    Posts:
    29
    Hi! @Kybernetik
    I'm using a LinearMixerTransition for my character's walking animation.
    When the threshold reaches 0.47, the WalkFwdLoop animation is played.
    However, the problem is that I run the LinearMixerTransition after the rotation animation ends.
    Because the direction of rotation affects which foot comes forward first, I need to alternate between the WalkFwdLoop and WalkFwdLoopMirrored animation clips, as shown in the attached image.
    So I'm temporarily assigning two LinearMixerTransitions and then running one of them depending on the left-right direction.
    Is this the right way? Is there a way to replace the animation clip of the LinearMixerTransition in real time? Thanks!
    upload_2023-10-14_23-30-11.png
     
  32. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    If you're going to also need mirrored versions of Run and Sprint, just using two transitions like that might be the way to go.

    Nested Mixers are also an option.

    Otherwise, mixerState.GetChild(1).Clip = ... would let you swap that particular clip.
     
  33. Cevalus

    Cevalus

    Joined:
    Aug 18, 2020
    Posts:
    6
    Hi Kybernetik,

    I was wondering if it was possible to pass data to animation events when playing clips. Right now, there's no easy way to pass data to animation events. Ideally, we could pass data when playing clips like this:

    Code (CSharp):
    1.  
    2. animancer.Play(clip, someData);
    3.  
    Then, on the receiver method, we could retrieve the data:

    Code (CSharp):
    1.  
    2. private void ReceiverMethod(SomeData someData)
    3. {
    4. ...
    5. }
    6.  
    Is something like that not possible??? It seems like such a huge limitation on the engine.
     
  34. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    There isn't really any way for something like that to be generalised without being notably inefficient.

    Most cases like that can be covered by closures:
    Code (CSharp):
    1. var state = animancer.Play(clip);
    2. state.Events.Add(x, () =>
    3. {
    4.     ReceiverMethod(someData);
    5. });
    6.  
    7. private void ReceiverMethod(SomeData someData)
    8. {
    9. }
    If that doesn't help, what's your actual use case? There might be a better way to approach it.
     
  35. heartshapedbox

    heartshapedbox

    Joined:
    May 27, 2018
    Posts:
    29
    Hi @Kybernetik,

    I have some questions about transition assets.
    1. If a prefab called human01 has multiple ClipTransitions, and 10 instances of human01 are created by instantiating this prefab, is it not necessary to use Transition Assets?

    2. After assigning the same Transition Assets to 10 characters, and declaring ClipTranstionAsset.Events.OnEnd = Foo;, when OnEnd is invoked, Foo is executed on only one character? And if i want Foo to be executed on each of the 10 characters, do i need to use UnShared?
    Thank you.
     
  36. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    1. It's up to you whether you want to use regular Transitions or Transition Assets in that situation.
    2. If every instance references the same Transition Asset then that line of code will have every character set the end event on the asset which will end up only containing the last one, then every character will play those same events with only the last character's Foo registered so they will all be triggering the last character's end event. And yes, the UnShared system is designed to avoid that exact problem.
     
  37. Royy212

    Royy212

    Joined:
    Aug 1, 2016
    Posts:
    33
    Hi Kybernetik,

    I think I found a bug, perhaps it's Unity but I'm not sure. I'm trying to play animations on a weapon crate that I've made in Blender (including the animations).

    When I quickly want to check if the animations are working in Unity I setup the 'Solo Animation' class paired with the animator on the object and run the game.

    The chest that I've made in Blender is made out of 3 objects.
    The 'main' part (parent), the lid (child of main part) and a small metal part attached to the lid (child of lid).
    If I attach the Solo Animation class + animator on the lid and I try to play the 'open lid' animation then nothing happens.

    It says that the GameObject is missing when I select the GameObject with the animator and then the clip I want to play in the Animation tab. I'm only able to get the animation to work if I move the class + animator on the 'main' part (the parent) of the crate.

    I tried placing the class + animation on another GameObject but then I get the same problem as placing the class + component on the lid.

    Here are screenshots of my setup: https://imgur.com/a/Qfa3JC4

    So to be clear, the animation does ONLY work if I place the Solo Animation class + Animator component on the PARENT of my GameObject.
    While the animation is made for the FIRST CHILD (after parent).

    Googling only gave me tips on how to rename the GameObject's name in the Animation tab where it says 'Missing....'
    But since the name is already correct I don't need to rename it.
     
  38. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    That all looks correct to me. Your asset is called Test Crate so the Animator should be on the Test Crate object and the animation says it animates Cube.001 so it will look for a child of the Animator with that name.

    If you still think it might be a bug, try playing your animation with a regular Animator Controller. If it has different behaviour to Animancer then it might be a bug.

    It's probably possible to set up your model to animate itself instead of its child, but I don't have any real experience with Blender or model exporting so I'm not sure how it could be done.
     
  39. Royy212

    Royy212

    Joined:
    Aug 1, 2016
    Posts:
    33
    Seems you are right, using an Animator Controller without using the Animancer give the same results. I expected to be able to place the Animancer Component or Animator Controller on the child object that is moving, but apparently that will give an error.

    Thank you.
     
  40. Royy212

    Royy212

    Joined:
    Aug 1, 2016
    Posts:
    33
    So I'm still trying to figure out how I can play both animations for my weapon crate using one animator. Since the metal part and the lid both need an animation to be played on. And I'm only able to place the animator on the 'main' part of my weapon crate.

    I've ticked Apply Root Motion on the Animator, my goal is to rotate the metal part using an animation I've made and KEEP the rotation that is done on the metal part. This part is attached to the lid of the crate. Now after the metal part is rotated I want to rotate the lid of the crate while KEEPING the rotation that is applied on the metal part, but this metal part's rotation immediately resets (probably) because it's all done using the same Animator.

    I've tried using one Animancer Component or two, also tried using only the Animator component.
    Is there a way using my setup to use one Animator and keep the rotations that are done using one animation on a GameObject while playing another animation on another GameObject.

    EDIT: I couldn't find any fix for using only one animator. So I ended up spliting the crate in 2 FBX objects. The main part with the lid plus it's animation and the metal part with it's animation.

    So now I'm able to use 2 animators and save the rotations applied to the lid and the metal part.
     
    Last edited: Oct 20, 2023
  41. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Layers might be what you're looking for. Using a second layer to play the second animation will mean it doesn't stop the first and can play them both at the same time.
     
    Royy212 likes this.
  42. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    Hi Kybernetik,
    I want to upgrade my code using your state machine coding.
    Last time, while I do not use state machine, my character can run / jump and attack at the same time.
    I simply play the attack animation midair and continue to apply air movement; result is fluid combat where character would not need to stop to attack.
    Now in the context of state machine coding, how can I do this combination the right way?
    I notice in the 3D gamekit example the character can't attack until she stops moving, so I skip that, also I don't find relevant info in the Examples folder.
    I think this is something about sub-state where you can be in Locomotion/Airborne and Attack state at the same time? Just don't know how to implement. Would like to hear your input on this.
     
  43. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    Spikebor likes this.
  44. Spikebor

    Spikebor

    Joined:
    May 30, 2019
    Posts:
    269
    Thank you, for now I'll implement actions like Attack, Skills casting etc as separated thing from state machine so they can live together.
     
  45. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    @Kybernetik I'm trying to use Linear Mixer Transition Object and wondering if there is any issue related to preview?
    When I click on Preview and try to change the "default parameter" it won't reflect until and close the preview and open the preview again. This actually makes it difficult to test with different values.

    Is this a known issue or am I missing something?
     
  46. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    The default value is applied when the mixer is first created, which only happens once when the preview is opened. If you want to see what different parameter values look like you can expand the mixer state near the bottom of the preview Inspector and change its Parameter field. That field's value is only for the preview so it won't be saved, but you can just find the value you want then copy it over to the Default Parameter field.
     
    Voxel-Busters likes this.
  47. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    1,832
    Wow it worked! Thanks for the quick response!
    It would be great if you just have a note at the default parameter that in preview mode we can test the value by expanding in the preview. It's not actually that easy to find.

    However, Thanks for the help! It's working great!