- Home /
Question by
SkullKing · Apr 01, 2015 at 01:18 PM ·
mecanimgetcomponents
State Machine Behaviour GetComponents does not exist, works fine in monobehaviour.
I am getting an error that says "'Getcomponents' does not exist in the current context" on the below State Machine Behaviour script.
the same syntax works fine in a monobehaviour. i do not now why it does not work in mecanim.
StateMachineBehaviour
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;
public class MecPMSendEvent : StateMachineBehaviour {
public string TargetFSMName;
public string EventName;
private PlayMakerFSM TargetFSM;
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
PlayMakerFSM[]temp= GetComponents<PlayMakerFSM>();
foreach(PlayMakerFSM fsm in temp){
if (fsm.FsmName==TargetFSMName){
TargetFSM=fsm;
break;
}
}
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
TargetFSM.Fsm.Event(EventName);
}
}
Comment
GetComponents
as its name suggests will get components on GameObject
s. Since your script inherits from State$$anonymous$$achineBehaviour
ins$$anonymous$$d of $$anonymous$$onoBehaviour
, that method does not exist.
in future, please post the complete error message which often contains line numbers, etc.
Answer by L42yB · Jul 06, 2018 at 09:13 PM
GetComponent only works on scripts that inherit MonoBehavior. Scripts that inherit StateMachineBehavior do not have a GetComponent function.