Script Loading order not working as expected


I was trying out an application which needed some library JS files. But didn’t get an expected result. I read somewhere on the forum to create a new script in the editor itself and copy paste the library content and place in “Script Order”. But no luck. (I had asked this question in - However, I found the scripts to come in order when I attach them to an entity. All worked great till now.
(I noticed the new editor updates the scene on script update - Great feature though).

Now when I try to update a particular script, it comes to the top of the order as seen in Inspector(Chrome 51) which eventually generates errors in run-time. Would be great if somebody could help me out with the process of script execution order or on how playcanvas handles it. Any kind of help is truly appreciated.


PS: Loading Order in the old editor is working fine. Problems only with the new editor

There is an issue with loading order atm, we are working to fix it.

1 Like

Shall be fixed now.
Thank you for reporting issue.

script loading order still doesn’t work as expected for me.

campGame should run before campUIbarbutton,
I’ve put console.log in both of the initialize methods, and campUIbarbutton always shows up first…

I need campGame to function as a singleton, sort of, but if I can’t rely on the order, then I can’t be sure the singleton exists in other objects’ initialize, which is annoying.

am I doing something wrong or misundestanding? or is it just buggy…

my script order:

the 2 scripts in question, notice the console.log…

the actual output, there’s 5 campUIbarbuttons in the scene and 1 campGame object…
notice that the buttons initialize first…

Load order is not related to the order/when the initialize function is called.

If you put a console.log at the top of each file, you should see that they are loaded in the correct order. The order that the initialize function is called is dependent on the entity hierarchy and when entities are enabled.

If you need something is dependent on running after another script’s initialize function, I recommend using postInitialize instead as described here: