Search Unity

Using Override Animation Controllers (NOT WORKING)

Discussion in 'Animation' started by Timberghost, Mar 6, 2019.

?

Good Way to Run a Animation System for different weapons in a game?

  1. Yes

    0 vote(s)
    0.0%
  2. No

    0 vote(s)
    0.0%
  1. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    Hello everyone, I am working on a system that makes every weapon in my game have a different set of animations using Unitys Override Animation Controller. Currently, I have my players Animator set up with two layers: Movement and Weapons. In my Game Currently I have a GameObject(Sword) that holds my Sword Model, ScriptedObject Information, and a Component for my Animator (Override). In my Override Controller I have set my Main Animator and it displays the values to interchange from my Movement and Weapons layer With the new animations in the Override controller. When my Game is started I press my keys that correspond to my attack layer and the default attacks show up, when I equip my Weapon (Enabling the Game Object Along with the Animator) and press my keys that correspond to my attack layer, the same animations appear as if the Override controller is not working. Any help would be appreciated as to why and how I can fix my Override controller

    Some Pictures


    Capture.PNG
    [Main Animator Component that holds the Movement and Attack Layer]


    Capture.PNG
    [Sword GameObject that Holds Animator Component that Runs Override Controller]



    Capture.PNG

    [Animator Override Controller (Not Overriding Defaults)]
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    The SmallSword override wraps the Player_AnimatorController and is supposed to replace it, not be played separately alongside it. Remove the Animator from the Sword and assign the SmallSword override as the Controller on your main Animator.
     
  3. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    So I should remove the Animator from my Sword? How would i be able to run the Override Controller from that point? could you give more detailed instructions? sorry I have been stuck on this issue for a while and im still fairly new to unity
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    Yes, a sword doesn't generally need to be playing an animation. You animate the character to move their hand and you put the sword as a child of the character's hand transform so that the hand moves the sword.

    By giving your character the SmallSword override controller, it will play the Player_AnimatorController normally (because that's what the override has as its base Controller) except that when it goes to play a clip called "Def.OutSlash" it will instead use "Def.Shield" (because that's the override you have assigned according to your screenshot).
     
  5. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    By Removing the Override Animation Controller from my Sword how is the Override controller supposed to be accessed I dont really have any sort of C# code running for this
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    As I said initially:
     
  7. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    Capture.PNG Capture.PNG
    Okay I removed the Animator Component On the Sword, When I read assign the SmallSword override as the Controller on your main Animator. I imagine taking The Animator on my Player and changing it from the Movement/Attack Animator and replacing it with the override animator?

    By doing this The Animator Controller I believe would still be able to run through the Override but then I cant Have different animation sets for different weapons? Sorry if im not understanding still new to unity and am very tired
     

    Attached Files:

  8. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    Yes, that's what I meant.

    If you have another AnimatorOverrideController for a different weapon, a script can assign it to the Controller field you have circled on the Player's Animator when you equip that weapon.

    I haven't actually used override controllers because I find the whole system to be heavily flawed, but I'm pretty sure that's how they're supposed to be used.
     
  9. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    Alright I Got this too work!!! thank you so much, this is a great start to a system for different animations depending on the weapon, however if you were doing a system like this what would your approach be since override controllers you see as heavily flawed?
     
  10. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    My signature has a link to my Animancer plugin which lets my scripts directly reference the AnimationClips they want to play without needing to set up states in an AnimatorController beforehand. So if each weapon in the game has a Weapon script attached to it, I would give that script serialized fields for each of the animations a weapon should have. Then each time a script wants to attack or do anything with a weapon-specific animation, it simply gets that animation from the currently equipped Weapon and plays it. If I set a different weapon as the equipped one, any future attempts to use the current weapon's animations will automatically start using the animations from the new weapon.
     
    hopeful likes this.
  11. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    514
    If you're using an AnimatorController, the only way to change clips at runtime is to use an override controller. If you want to avoid the override controller entirely, you need to use the Playables API (which is what Animancer uses).

    Having the animations as inspector fields in your own script (either as a ScriptableObject asset or a MonoBehaviour component) is definitely the approach I'd recommend because it lets you choose how to tackle each situation to best fit your needs.
     
    Timberghost likes this.
  13. Timberghost

    Timberghost

    Joined:
    Jun 26, 2018
    Posts:
    10
    Alright, Awesome! Thank you So much for your help I greatly appreciate it