Wait for entity to be loaded

I am struggling with this.
I have entity which has some descendants (video player, UI elements etc. ) and it is disabled by default. In some moment i set it the entity enabled = true;
Is there a way to make sure that some functionality in script executes just after all entity’s children are properly rendered? So it doesn’t show when for example video player is not ready yet(rendered, video not loaded) ? Let’s say i want to get alert() message when everything is loaded

Hi @Lukas_Zahumensky,

One way to approach this is using postInitialize instead of initialize in your script. It will fire after all entities finished firing their initialize method. Check this manual page on how that works:


Now if you are doing async things like loading an asset, so your entities might take a while to load, you can use custom events to inform your parent entity that “Hey, we the children are ready”.

Check this manual page on how to communicate between your script instances:


1 Like

well I have an app where I show rooms interior and sometimes I switch between rooms by disabling the current room and enabling room i want to show.
Problem is when I disable room I show blackscreen and want to keep it there until the second room isn’t fully loaded and ready with all its content (rooms have som children entities e.g. video players etc.)

One thing you might want to try is disabling autoRender before disabling the room you want to hide:

this.app.autoRender = false;

and then re-enabling it once your next room is ready:

this.app.autoRender = true;

Otherwise, your best bet might be to have something behind each room’s geometry too look at so you aren’t plagued by a black screen. You could even cover it with a UI element during the switch.


but how can I find out if all contents of another room are fully loaded?

This is what I want:

  1. get in black screen
  2. disable current room
  3. enable room I want to go in
  4. wait in black screen until room is fully loaded with all its children entitites
  5. when loaded disable blackscreen

Best approach I’ve found os to tag all the assets in the room with something like ‘room X’ and between step 2 and 3, use ‘this.app.assets.findByTag’ to get all the assets that have been tagged with ‘room X’ and load them.

Once they have been loaded, then enable the room/load scene.

A simplified version of this approach can be found here: Load multiple assets at runtime | Learn PlayCanvas

This won’t wait for your videos to be ‘ready’ though, that requires separate logic as Leonidas has mentioned.

1 Like

hey @yaustar I have been struggling with this solution for weeks… thank you very much I managed to achieve my goal with help of your last comment. Thank you!

Forgot to say that our Seemore project does something similar: https://playcanvas.com/editor/scene/741889