I need to access the application root entity (pc.app.root) from a code not inside a ScriptType.
This code is called inside a ScriptType.initialize method but pc.app is still undefined.
I tried also postInitialize but is the same.
When pc.app is defined? There is an event to know when the game is started outside of ScriptType?
Yes, this is what I did at the end and I initialized my service class with it from within the ScriptType.
But is it possible to completely avoid a ScriptType and just execute some code when PlayCanvas application is ready?
Now I have a script bound to an entity just to get access to the app itself.
I think pc.app is set when the first frame starts but you can try pc.Application.getApplication() instead which is set as soon as an application is created.
Yes, it worked. Thank you. pc.app is set inside a tick() method and is executed at the end of all the initialize and postInitialize methods.
Please help me to understand better the core. The method pc.Application.getApplication() returns the current application if an id is not specified.
What is the situation and the use case to have multiple application?
Is it when on the same page we need multiple canvases?
The editor exports a fullscreen app, so I guess this can be done only in some custom configurations.
You can theoretically have multiple applications in one page on different canvases. We don’t have many examples of that happening though usually people just embed multiple iFrames which is a bit more stable and easy to cleanup.