Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: TokyoDan on April 13, 2014, 01:12:34 AM

Title: Which Start is executed first?
Post by: TokyoDan on April 13, 2014, 01:12:34 AM
I know that the START event of an FSM is executed whenever the FSM is created in a scene or when a scene is first loaded. But...

Say I load a scene with one GameObject, The GameObject has one script component and one FSM component. Which Start is called first? The Start() function of the script, or the START event of the FSM?
Title: Re: Which Start is executed first?
Post by: Lane on April 14, 2014, 07:52:50 AM
Whichever is on the uppermost in the inspector stack.
Title: Re: Which Start is executed first?
Post by: jeanfabre on April 14, 2014, 08:09:28 AM
Hi,

 Not necessarly, You can not guarantee execution order in Unity. If you move a component up the stack, it won't change it's execution compare to that stack.

bye,

 Jean
Title: Re: Which Start is executed first?
Post by: Lane on April 14, 2014, 08:32:48 AM
Are there some overrides that might be used to break the top-down flow or something? So far its been reliable for me. The only exception I can think of is if 5 scripts on the bottom have a Start function and 5 scripts on the top only use Update... then the bottom ones will run their Start() first and Update will be run afterwards.
Title: Re: Which Start is executed first?
Post by: jeanfabre on April 14, 2014, 08:39:39 AM
Hi,

 yes, Unity has a setting to define script execution order, that's where things get tricky and dangerous... Cause the execution order is based on the class, not the stack order... so very prone to hard-to-find bugs :)

Typicall, if the execution order is important, create your own "INIT" or something can call fsm manually, this will a lot more reliable in the end.

bye,

 Jean
Title: Re: Which Start is executed first?
Post by: Lane on April 14, 2014, 08:53:12 AM
Good to know! =)