playMaker

Author Topic: LoadLevel and BroadcastEvent Action Bug [FIXED]  (Read 5459 times)

djinni68

  • Playmaker Newbie
  • *
  • Posts: 4
LoadLevel and BroadcastEvent Action Bug [FIXED]
« on: April 16, 2011, 09:10:06 AM »
I have a script that reloads the same level if certain goals have been achieved.  However, once the level reloads (via Application.LoadLevel) the first FSM that executes a Broadcast Event Action gets the following debug log entries (the last one is the error):

BroadcastToAll
UnityEngine.Debug:Log(Object)
HutongGames.PlayMaker.Actions.BroadcastEvent:BroadcastToAll() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:42)
HutongGames.PlayMaker.Actions.BroadcastEvent:OnEnter() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:34)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:Continue()
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

to: FSM
UnityEngine.Debug:Log(Object)
HutongGames.PlayMaker.Actions.BroadcastEvent:BroadcastToAll() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:48)
HutongGames.PlayMaker.Actions.BroadcastEvent:OnEnter() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:34)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:Continue()
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

to: FSM
UnityEngine.Debug:Log(Object)
HutongGames.PlayMaker.Actions.BroadcastEvent:BroadcastToAll() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:48)
HutongGames.PlayMaker.Actions.BroadcastEvent:OnEnter() (at Assets/PlayMaker/Actions/BroadcastEvent.cs:34)
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:Continue()
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
HutongGames.PlayMaker.Actions.SendMessage.DoSendMessage (UnityEngine.GameObject go) (at Assets/PlayMaker/Actions/SendMessage.cs:56)
HutongGames.PlayMaker.Actions.SendMessage.OnEnter () (at Assets/PlayMaker/Actions/SendMessage.cs:36)
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState)
HutongGames.PlayMaker.Fsm.DoTransition (HutongGames.PlayMaker.FsmTransition transition, Boolean isGlobal)
HutongGames.PlayMaker.Fsm.ChangeState (System.String eventName)
HutongGames.PlayMaker.Fsm.Event (HutongGames.PlayMaker.FsmEvent fsmEvent)
HutongGames.PlayMaker.Actions.BoolTest.OnEnter () (at Assets/PlayMaker/Actions/BoolTest.cs:26)
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.EnterState (HutongGames.PlayMaker.FsmState state)
HutongGames.PlayMaker.Fsm.SwitchState (HutongGames.PlayMaker.FsmState toState)
HutongGames.PlayMaker.Fsm.DoTransition (HutongGames.PlayMaker.FsmTransition transition, Boolean isGlobal)
HutongGames.PlayMaker.Fsm.ChangeState (System.String eventName)
HutongGames.PlayMaker.Fsm.Event (System.String fsmEventName)
HutongGames.PlayMaker.Actions.BroadcastEvent.BroadcastToAll () (at Assets/PlayMaker/Actions/BroadcastEvent.cs:49)
HutongGames.PlayMaker.Actions.BroadcastEvent.OnEnter () (at Assets/PlayMaker/Actions/BroadcastEvent.cs:34)
HutongGames.PlayMaker.FsmState.OnEnter ()
HutongGames.PlayMaker.Fsm.Continue ()
HutongGames.PlayMaker.Fsm.Update ()
PlayMakerFSM.Update ()
« Last Edit: October 06, 2011, 03:30:17 PM by alexchouls »

djinni68

  • Playmaker Newbie
  • *
  • Posts: 4
Re: LoadLevel and BroadcastEvent Action Bug
« Reply #1 on: April 16, 2011, 09:20:27 AM »
Quick Followup - If I debug the FSM using the PlayMaker Editor, during the LoadLevel command, I do not experience this issue.  Is this a case of a static variable within the Huton Games framework losing its connection to the various FSMs in the scene?  I'm guessing its Fsm.FsmList?
« Last Edit: April 16, 2011, 09:32:04 AM by djinni68 »

djinni68

  • Playmaker Newbie
  • *
  • Posts: 4
Re: LoadLevel and BroadcastEvent Action Bug
« Reply #2 on: April 16, 2011, 12:06:24 PM »
I may have found my own solution for this issue.  I've written a simple class that checks the Fsm.FsmList, and puts the count into a static variable.  Each time the scene resets, this variable is compared to the actual count, and if they are different, we reset the FsmList using the SanityCheck function (at least, I think that's what it does!).  Here's the code, and you just have to add it to a single object in your scene.

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class PlayMakerStatics : MonoBehaviour {
private static int fsmCount = 0;
private int fsmCurrentCount = 0;

// Use this for initialization
void Awake () {
if(fsmCount == 0) { // First time executing the script!
fsmCount = Fsm.FsmList.Count;
fsmCurrentCount = fsmCount;
}
else if (fsmCurrentCount != fsmCount) {
Fsm.SanityCheckFsmList();
fsmCount = Fsm.FsmList.Count;
fsmCurrentCount = fsmCount;
}
}

// Update is called once per frame
void Update () {

}
}

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: LoadLevel and BroadcastEvent Action Bug
« Reply #3 on: April 16, 2011, 05:13:45 PM »
Thanks! I need to do a similar check within playmaker - will add it to the next update.

SanityCheck does what you think it does. There are some editor events that are hard to catch in Unity, so SanityCheck is the fallback to make sure the FsmList is good...

djinni68

  • Playmaker Newbie
  • *
  • Posts: 4
Re: LoadLevel and BroadcastEvent Action Bug
« Reply #4 on: April 16, 2011, 08:36:53 PM »
Happy to lend a hand, Alex.  Thanks for getting this into PlayMaker!

*EDIT* I'm an idiot and somehow thought someone named "Chris" responded.  My bad!
« Last Edit: April 16, 2011, 11:17:43 PM by djinni68 »