Thanks for the quick reply. I tried putting the call inside OnEnter(), but no dice. Still getting a null reference exception when I start the scene. Is there a problem with using the GameObject.FindObjectWithTag() function in a custom action? The interesting thing is that the game still runs fine...it ends up working when my character moves to another state and then back. It seems like when the FSM is initially loaded, it can't find the GameController object.
Here is my updated script:
using UnityEngine;
using System;
namespace HutongGames.PlayMaker.Actions {
[ActionCategory("Custom")]
public class PLYMKRUnlockPlayerAttack : FsmStateAction {
public override void OnEnter() {
GameController gameController = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameController>();
gameController.UnlockPlayerAttack();
}
} // end class
} // end namespace
I've also attached a pic of my state machine in PlayMaker. The error is happening in the first state (PlayerOutOfRange), which is where the unlock attack custom action gets called. No idea why this seemingly trivial thing is throwing an error.
Here is the call stack as well:
NullReferenceException: Object reference not set to an instance of an object
GameController.UnlockPlayerAttack () (at Assets/08-Scripts/GameController.cs:221)
HutongGames.PlayMaker.Actions.PLYMKRUnlockPlayerAttack.OnEnter () (at Assets/08-Scripts/Actions/PLYMKRUnlockPlayerAttack.cs:16)
HutongGames.PlayMaker.FsmState.ActivateActions (Int32 startIndex)
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState)
HutongGames.PlayMaker.Fsm.UpdateStateChanges ()
HutongGames.PlayMaker.Fsm.Start ()
HutongGames.PlayMaker.Fsm.ProcessEvent (HutongGames.PlayMaker.FsmEvent fsmEvent, HutongGames.PlayMaker.FsmEventData eventData)
HutongGames.PlayMaker.Fsm.Event (HutongGames.PlayMaker.FsmEventTarget eventTarget, HutongGames.PlayMaker.FsmEvent fsmEvent)
HutongGames.PlayMaker.Fsm.Event (HutongGames.PlayMaker.FsmEvent fsmEvent)
PlayMakerFSM.OnLevelWasLoaded ()
Ideally I would like to get this working without having to use the SendMessage. Thanks for the help!