When is a scene's create function called when you use the ScenePlugin's launch function?

Here is an abridged setup for a problem I am noticing in my game.

class BaseScene extends Phaser.Scene{
  create() {
   //using the scene plugin to launch the UI scene (under).
   this.scene.launch("UIScene");
   this.ui = this.scene.get("UIScene");
  }
}

class ChildOfBase extends BaseScene {
  create(){
   //this is the function that "launches" the UI scene
   super.create();
   
   //issue!!
   this.ui.myObject// <--- THIS IS UNDEFINED
  }
}

class UIScene extends Phaser.Scene {
  constructor(){
    super({key:"UIScene"});
  }
  create(){
   this.myObject = this.add.image()//regular image / sprite / etc add
  }
}

The problem is with accessing the myObject property on the UIScene that exists as a property on the BaseScene.

Sorry that it’s a bit complicated, but basically the UIScene’s create function seems to occur AFTER the child of the BaseScene calls its create function, even though the parent scene’s create function launches the UIScene.

There are many ways to get around this, and it’s not game-breaking, but I’d like to know if there’s a reference as to when scenes that are added with the ScenePlugin fire their create() functions.

A diagram I found on the notes makes it seem like I should expect the UIScene create() function to already have fired by the time my child needs to access it’s properties, unless I’m reading it wrong. Link Phaser3 Scene Notes

The “launch” happens during the next game step.

1 Like

Thanks, is there anywhere I can see documentation on this? Devlog / Notes etc. ?

Also, is there a way to recommend waiting exactly one game step to execute a scene’s create function until that scene is launched?

Phaser Scenes Summary of course :wink:

It’s in CHANGELOG but the API docs may be behind.

You can listen to UIScene’s create event.

1 Like

Awesome! Thanks so much, this is perfect!