playMaker

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

TokyoDan

  • Playmaker Newbie
  • *
  • Posts: 9
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: 2511
  • Mender of the past
    • 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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
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: 2511
  • Mender of the past
    • 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.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
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: 2511
  • Mender of the past
    • Cleverous
Re: Which Start is executed first?
« Reply #5 on: April 14, 2014, 08:53:12 AM »
Good to know! =)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D