public async sceneOpened(): Promise {
console.log(“Scene has been opened”);
// Any async operations can go here…
this.onInitialSceneLoaded?.invoke()
}
public async sceneClosing(): Promise {
console.log(“Scene is closing”);
// Any async operations can go here…
}
}
I have attached this script to root of the scene object still i don’t get console message on scene opened. Please help on this issue
awake or start would both work - I think start would be better/preferred to not call methods on other components before their own awake method has been called
It will work if you have multiple scenes and you’re using the SceneSwitcher component to load / unload them. Only the SceneSwitcher calls those methods right now.
Or add the SceneLoader component you made to the Root gameobject of the Loading scene - but I think it might not yet work in this case (when you export a scene) because it currently only checks one root object. I’ll have to test and fix this
Got it. Assuming you have only one player object in the main scene you can add a script to your player roughly like so:
export class Player extends Behaviour
{
static players: Player[] = [];
static onLobbyLoaded() {
foreach(const pl of players) {
// call a method on the player or trigger the animator on the player e.g. pl.gameObject.getComponent(Animator)?.setTrigger("lobbyLoaded");
}
}
awake() { Player.players.push(this) }
onDestroy() { Players.players.splice(Players.players.indexOf(this)) }
}
and then your lobby scene could have a script like: