Playmaker Forum

Bug Reporting => PlayMaker Bug Reporting => Topic started by: Murcho on March 29, 2011, 10:08:07 PM

Title: Load Level action
Post by: Murcho on March 29, 2011, 10: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.
Title: Re: Load Level action
Post by: e.Ko on March 31, 2011, 10: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...
Title: Re: Load Level action
Post by: Murcho on April 03, 2011, 08: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.
Title: Re: Load Level action
Post by: Alex Chouls on April 03, 2011, 09: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?
Title: Re: Load Level action
Post by: scritch on April 18, 2011, 07: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?
Title: Re: Load Level action
Post by: Alex Chouls on April 18, 2011, 09: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...
Title: Re: Load Level action
Post by: qholmes on February 06, 2012, 01:39:29 PM
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
Title: Re: Load Level action
Post by: kdsh7 on March 13, 2012, 07: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!
Title: Re: Load Level action
Post by: kdsh7 on March 13, 2012, 08: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.