State Driven Camera

So doing this lecture, I’m also having an issue with my camera not switching back to the FreeLookBlendTree. I hit tab to swap in, it changes cameras, removes all movement logic / animations as expected, but when I hit escape I’m stuck in a t-pose and the camera doesn’t swap back so what I gather is I’m successfully changing states, and when I change states I’m swapping from the freelook blend tree to the targeting blend tree but when I go to switch back I’m successfully changing states again but I’m stuck in the targeting blend tree. I’m also throwing the following warning:

I can only assume that means that it’s assigning the wrong int to the blend tree?

I’ve looked over the lecture resources to make sure my code matches and I can’t seem to find the error (plus my state driven camera object seems to be configured correctly). Here’s the relevant code assigning the int and playing the blend tree’s.

// variable assignment in PlayerTargetingState.cs  
  private readonly int TargetingBlendTreeHash = Animator.StringToHash("TargetingBlendTree");

// within Enter() of PlayerTargetingState.cs
        stateMachine.Animator.Play(TargetingBlendTreeHash);

// variable assignment in PlayerFreeLookState.cs
    private readonly int FreeLookBlendTreeHash = Animator.StringToHash("FreeLookBlendTree");

// within Enter() of PlayerFreeLookState.cs
        stateMachine.Animator.Play(FreeLookBlendTreeHash);

It looks (without seeing a screenshot of the Animator) like your States in the Animator may not be named “TargetingBlendTree” and “FreeLookBlendTree”. I suspect, since you’re saying that the issue is returning to the FreeLookBlendTree, that the state is really named “FreelookBlendTree”, but can’t be positive.

Paste in a screenshot of your Animator if this didn’t fix things for you.

It was incredibly hard to see, but you are right there was a space in the animator making the string “FreeLookBlend Tree”. I changed it and the animator was working perfectly, of course then it freaked me out a bit because then the cinemachine stopped working right but by changing it in animator it knocked out the state from the state driven camera. Got it working now though, thanks!

That’s one of the more common issues with animators, because even with hashing the strings in code, there is still no solid method of validating that the string you’re using in code matches the state or Trigger in the Animator. Glad you’ve got it working again!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms