x


Two monobehaviour scripts attach to one gameobject and the Update order predicable?

If I attach two monobehaviour scripts to one GameObject,is the Update order predicable?

For example: First I attach aaa.cs and then attach bbb.cs, unity engine will call aaa.Update() bbb.Update() ??

Very thanks.

more ▼

asked Feb 20 '12 at 04:11 PM

chansey gravatar image

chansey
16 2 2 3

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

The order in which Update is called is undefined, so no, the order is not predictable, unless you use the script execution order which MIke mentioned.

more ▼

answered Feb 21 '12 at 01:27 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(comments are locked)
10|3000 characters needed characters left

Update is called once per frame, I don't think that you would be able to predict which script is called first. Just did some testing and the script I attatched to the game object last got called first, but this can also be random, I'm not sure at all. May I ask what you need this for? :)

more ▼

answered Feb 21 '12 at 01:16 AM

Artifactx gravatar image

Artifactx
36 1 4 7

(comments are locked)
10|3000 characters needed characters left

You can set the script execution order in Unity, which according to the 3.4 release notes includes Update() commands.

Tutorial on how to set this is here

more ▼

answered Feb 20 '12 at 05:29 PM

runonthespot gravatar image

runonthespot
514 19 21 36

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3329
x495
x55

asked: Feb 20 '12 at 04:11 PM

Seen: 868 times

Last Updated: Feb 21 '12 at 01:27 AM