Set Up Component Access to StateMachineBehaviour. HELP

Hi to all.
I don t know why it seems doesn t work. What am i doing wrong?

Please help

Not going to be a lot of help without some very specific error text to go on.

“Looks great to me!”

Unity gives to me just a NullReferenceError for the PlayerController component in the StateMachineBehaviour

Don’t cache the PlayerController to the StateMachineBehaviour. StateMachineBehaviours work best if they can forget about the gameobject/component they are working with when they finish each function. They are embedded inside project assets, so unless you understand how they work its dangerous for you to have them hold references to anything in the scene, like that PlayerController.

StateMachineBehaviours don’t link themselves to just one instance animator. The only window they have to the object thats currently using the StateMachineBehaviour is the passed in Animator variable. you can do one of two things. call var pl = _anim.GetComponent() and check that way. or send a message back through the animator to tell the playerController to figure out how to set the integer.

Ok, I took a break and i just realized that I m stupid.
I was using the same behaviour in multiple states on the animator, so the set up of the component was ok only in the first state. Now the set up it s fine. My bad.

please read my post. its dangerous to simply cache a specific component like this.

Edit: to clarify this very instance doesn’t seem like it would cause too much issue, cause it seems only one gameobject will ever use it. but its just plain bad practice and it will cause all sort of errors if you try to extend this practice to things like enemies

Thank u for the warning. I just started to work with StateMachineBeahviour, and yes i got the point. I will find another way i think. Thank s again!