StateMachineBehaviors reside on the animator component itself, not a on a game object in the scene like MonoBehaviors. The side effect is that it’s unaware of objects outside that sope, like the hiearchy (aka the scene). So pretty much everything usefull.
Your only link to the outside world is through the animator property you receive as a parameter on the OnState functions.
So if for example you want to run a function from a script on the game object the animator is attached to you do something like this:
using UnityEngine;
public class StateMachineGobalVariables : StateMachineBehaviour {
public scriptClassName script;
override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
script = animator.gameObject.GetComponent<scriptClassName> ();
script.PublicFunctionName ();
}
}
Unfortunatly you end up using GetComponent way more than you would like.
You can also use:
GameObject.Find
GameObject.FindGameObjectWithTag
GameObject.FindGameObjectsWithTag
GameObject.FindWithTag
But we both feel the same about using those.
Personally I’m going to try setting a few global variables on my idle state (default state on startup) using a StateMachineBehavior too see if that can help prevent using GetComponent. Just haven’t gotten around to trying it yet. Hopefully behaviors inside the state machine can see each other otherwise that plan is dead.