Awake called in different order in standalone build

I had this bug today, and wanted to post how I fixed in case some has a similar issue in the future.

I have a Cage prefab with a Player gameobject nested inside it.
In the editor the nested Player script Awake() is called first, followed by Cage script awake(), however, when I create a standalone build, the execution order switches around: First the Cage Awake() is called, followed by the Player Awake()

After a lot of debugging I resolved the issue by simply duplicating the entire cage prefab, deleting the original and renaming the duplicate.
Hope this helps!

1 Like

This is not a bug.

To solve this you need to use Execution order when scrip is selected in Project list.

Okay, duplicating the prefab only works until I close unity. When I reopen unity the issue returns :confused:

Are you saying that I must add the scripts to the Script Execution Order in Project settings because I have done that.

Besides, even if the execution order is not set up, it should still execute in the same order when running in the editor as it does when running as a stand alone build? To be clear, my issue is not the general order that the scripts execute in, I don’t mind which runs first, the issue is that they execute in a different order when I create a stand alone, and I need it to be deterministic,
This hasn’t been an issue for the last 2 months, but suddenly today its executing in a different order in the standalone

Still an issue, randomly happened to my project as well, only in standalone execution order is ignored.

Still an issue. Project settings → Script execution order in editor is not respected by the build.

Please file a bug report so we can investigate