My game has two extensions as shown in the image below.
All of those extensions have the onFirstSceneLoaded lifecycle function.
However, the onFirstSceneLoaded functions are being called in a different order than I intended. I want CommonUtils’s onFirstSceneLoaded function to be called first because TetrisUtils’s onFirstSceneLoaded use internally CommonUtils’s functions, but TetrisUtils’s onFirstSceneLoaded function is called first.
How do I adjust the calling order of onFirstSceneLoaded functions for multiple extensions?
Should I change the order of the extensions described in game.json directly with a text editor?
Please tell me anything.
Right click on 3dots button and move up
I tried as you told but CommonUtils is still called after TetrisUtils.
If it were me I would move all of your “OnFirstSceneLoaded” logic for each extension into a new function called “init” or something like that. Then in “CommonUtils” add a new OnFirstSceneLoaded block that calls “init” in order on each of your extensions. This way you don’t have to rely on the internal call order.
Yes, it’s possible to do that. But I don’t want to deal with any specific business logic in “CommonUtils”.
What is the basis for the order in which the extensions’ onFirstSceneLoaded are called?
I think the order is linked to the naming of the extension. Maybe in alphabetical order or reverse alphabetical order.
It turns out that it’s not related to the alphabetical order
I think the extension’s priority to be loaded should be configurable so that it can be changed.
I eventually decided to follow a similiar way that @krunkster suggested. it’s because it seems more reasonable not to depend on the internal calling order. So I added another extension named Start-Up and its onFirstSceneLoaded calls other extensions’ initialize functions as follows. Thank you all
In what order are the extensions in the game file?
The loading order should have a logic^^
The order of the extensions in the game file corresponds the order defined in “Project Manager> Function/Behavior”.
The method I mentioned using the startup extension doesn’t work. I’m just going to manually call the Initialize action of each extenion in the first scene.
An idea for the loading order of extensions @4ian ?
normally, the extension files should be loaded in alphabetical order, as every function is exported as a JS file with the name of the extension and of the function and is used as a normal JSExtension include, so I don’t get why it isn’t the case
Extensions loading order is unspecified. In practice, avoid as much as possible relying on the initialization of other extensions.
Note that in the future we could add something to allow extensions to explicitly declare a dependency on another extension, and then ensure extensions are loaded in the reverse order of dependency (we first load the extensions that are dependencies of others) (that’s called a “topological order”).
We would also need to prevent circular dependencies, and maybe automate this so that you don’t need to make this list of dependencies by yourself if you’re just using traditional actions/conditions.