playMaker

Author Topic: Load Level action  (Read 9849 times)

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
    • View Profile
Load Level action
« on: March 29, 2011, 07:08:07 PM »
There is a little bit of inconsistency with the Load Level action.  When using it in an FSM, and attempting to use the LoadedEvent field, it isn't fired off, because as soon as the level is loaded, the START global event is fired, causing the FSM to revert to it's start state.

I'm not sure how you would go about changing this behavior, but it's probably something worth looking at.

e.Ko

  • Administrator
  • Playmaker Newbie
  • *****
  • Posts: 13
    • View Profile
Re: Load Level action
« Reply #1 on: March 31, 2011, 07:33:19 AM »
I'm not sure I follow... I think I see the problem, but need to play with a scene to be sure...

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
    • View Profile
Re: Load Level action
« Reply #2 on: April 03, 2011, 05:56:25 PM »
Step by step the issue is:

1. Load Level action runs, and loads a new level
2. Start Global Event is fired
3. FSM changes state from the state the Load Level action state, to the Start State of the FSM
4. LoadedLevel Event never fires due to FSM leaving the state.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3630
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Load Level action
« Reply #3 on: April 03, 2011, 06:43:20 PM »
Hmmm, the Load Level action adds DontDestroyOnLoad (exposed as an option in 1.1). I assumed that DontDestroyOnLoad would leave a game object unchanged when a level was loaded, but it seems like the game object is reset on load...? IOW Unity calls OnEnable on load, which sends the Start Event.

That would explain the behaviour, and would render the LoadedEvent kind of useless :(

If you get a chance can you verify that a regular script on a game object with DontDestroyOnload has OnEnable called when a level is loaded?

scritch

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 11
    • View Profile
Re: Load Level action
« Reply #4 on: April 18, 2011, 04:43:44 PM »
I ran into this today.  Tried what you asked below, and sure enough, OnEnable() is called on a test script attached to the same object the FSM is attached to one level loaded happened.

public class OnEnableTest : MonoBehaviour {
   void OnEnable()
   {
      Debug.Log("WOOPIE");
   }
}



Hmmm, the Load Level action adds DontDestroyOnLoad (exposed as an option in 1.1). I assumed that DontDestroyOnLoad would leave a game object unchanged when a level was loaded, but it seems like the game object is reset on load...? IOW Unity calls OnEnable on load, which sends the Start Event.

That would explain the behaviour, and would render the LoadedEvent kind of useless :(

If you get a chance can you verify that a regular script on a game object with DontDestroyOnload has OnEnable called when a level is loaded?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3630
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Load Level action
« Reply #5 on: April 18, 2011, 06:12:55 PM »
Thanks for confirming this. Guess I'll remove the Loaded Level event! A bit of a shame that Unity behaves this way, makes it a little harder to make an FSM that controls level loading. I'll document this behavior in the action reference...

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
Re: Load Level action
« Reply #6 on: February 06, 2012, 11:39:29 AM »
So i was just using the Load Level Action...  i see that there is still a Loaded Event here? Does it work?

I was trying to figure out what the Dont Destroy On Load was for. I assume it is for this object in particular so it can continue controlling?

But does it work?

Q

kdsh7

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Load Level action
« Reply #7 on: March 13, 2012, 04:57:13 AM »
I've been having this issue too - does this mean that having the FSM control level loading still isn't possible? Playmaker seems perfectly suited for organising levels and game flow so it'd be a real shame if we couldn't use it for that!

kdsh7

  • Playmaker Newbie
  • *
  • Posts: 7
    • View Profile
Re: Load Level action
« Reply #8 on: March 13, 2012, 05:17:10 AM »
aha! Just noticed there's a "Reset On Disable" toggle in the FSM settings. That fixes it. Hopefully this'll help somebody else.