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