Search Unity

Switch blend trees?

Discussion in 'Animation' started by GameCodeEdit, Sep 1, 2017.

  1. GameCodeEdit

    GameCodeEdit

    Joined:
    Aug 5, 2017
    Posts:
    10
    so I'm making a third person shooter game and I made this blend tree with animations for the character moving around while holding a gun.

    But now he's not always going to be carrying a gun and I want another blend tree with animations without him holding a gun.

    How would I switch the blend trees for when he's holding a gun and when he's not? Thanks! :)
     
  2. froilan_dE_dios

    froilan_dE_dios

    Joined:
    Jul 28, 2015
    Posts:
    17
    maybe you need to research on state machines. Enum and Switch will be your new best friends
     
  3. froilan_dE_dios

    froilan_dE_dios

    Joined:
    Jul 28, 2015
    Posts:
    17
  4. uriyeah55

    uriyeah55

    Joined:
    Apr 8, 2015
    Posts:
    4
    I know it's super duper late, but maybe someone finds this thread in a future anyway:

    I got the same problem in a 2d project, my character has the skill to throw a boomerang, and while she runs around with the boomerang away it isn't in her hand. And yes, I'm also using a Blend Tree.

    What I did it is to add the animations without the weapon in the Animator Controller, but assigned a different Blend Tree. This second one carries all the animations without weapons (make sure to name everything accordly).

    Create a bool variable in the Animator Controller. You can call it "Holding Weapon" and it has transitions to the animations holding a weapon. To switch it, just change the value of this bool via script with:

    player.gameObject.GetComponent<Animator> ().SetBool ("HoldingWeapon", false);

    In the Animator Controller, you now only have to link the animations with the first blend tree and the second one, using the transition condition of the Holding Weapon bool.

    Sorry if the explanation is messy, it's really logical but confusing to say. Hope you had luck out there!