playMaker

Author Topic: Which Start is executed first?  (Read 1627 times)

TokyoDan

  • Playmaker Newbie
  • *
  • Posts: 9
    • View Profile
Which Start is executed first?
« 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?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2498
  • Mender of the past
    • View Profile
    • Cleverous
Re: Which Start is executed first?
« Reply #1 on: April 14, 2014, 07:52:50 AM »
Whichever is on the uppermost in the inspector stack.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15440
  • Official Playmaker Support
    • View Profile
Re: Which Start is executed first?
« Reply #2 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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2498
  • Mender of the past
    • View Profile
    • Cleverous
Re: Which Start is executed first?
« Reply #3 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.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15440
  • Official Playmaker Support
    • View Profile
Re: Which Start is executed first?
« Reply #4 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

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2498
  • Mender of the past
    • View Profile
    • Cleverous
Re: Which Start is executed first?
« Reply #5 on: April 14, 2014, 08:53:12 AM »
Good to know! =)