Author Topic: Component Execution Order  (Read 2417 times)

DevMan5000

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 22
    • View Profile
Component Execution Order
« on: December 29, 2014, 04:14:20 PM »
Hi, I am still a unity newbie.

I have a "Highlight" script that runs and grabs the text from a label and creates a duplicate "highlight" label over it. The Label makes use of UILocalize. Unfortunately, I'm seeing in one label UILocalize gets called BEFORE my script and in another label instance UILocalize gets called AFTER my script.

If it gets called AFTER my script, then my Highlight script doesn't work because it is copying whatever contents were in the label before the UILocalize got called.

In both instances, my highlight script component is BELOW the UILocalize component in the inspector, which I thought would ensure execution order.

Is there something I am missing?

DevMan5000

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Component Execution Order
« Reply #1 on: December 29, 2014, 04:27:30 PM »
As a sanity check, I deleted the label where the UILocalize executed AFTER my highlight script. I copied the label which worked correctly (had UILocalized execute before my highlight script).

I figured that undoubtedly I would see consistent behavior at that point, but again, I saw that one label had UILocalize get called before the highlight script and one label had UILocalize get called AFTER the highlight script.

[scratching my head]

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Component Execution Order
« Reply #2 on: December 30, 2014, 02:39:50 PM »
You should simply change the script execution order for your custom script.

DevMan5000

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 22
    • View Profile
Re: Component Execution Order
« Reply #3 on: December 30, 2014, 04:20:51 PM »
Ok so I went to: Edit -> Project Settings -> Script Execution Order

I didn't see UILocalize on there so I added it to the list. I also added my WordHighlight script below that. That seems to have fixed my issue, so thank you.  :)

So to clarify, does the order of the components (top to bottom) on a game object matter at all in terms of execution order? Unity lets you move components up/down and reorder them. What is the use in that if it doesn't affect execution order?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Component Execution Order
« Reply #4 on: December 31, 2014, 03:45:46 PM »
No need to add UILocalize, just your script. You will need to consult the Unity's documentation for the last question.