Tiitouaan
18 days agoMember
Why is the start() method not triggered ?
Hello,
My PlayerManager is attaching a HUD to the player's head when he joins the world :
private handleOnPlayerEnterWorld(player: hz.Player): void {
// Handle double join messages
if (!this.gamePlayers.get(player)) {
const pData = this.gamePlayers.addNewPlayer(new PlayerData(player, this.props.initialHealthForPlayer, this.props.coolDownInMs));
console.log(`PlayerManager: New player joined world: ${player.name} with id ${player.id}`);
// Spawn du HUD personnel
if (this.props.hudPrefab) {
console.log("PlayerManager: Spawning HUD for player " + player.name);
this.world.spawnAsset(this.props.hudPrefab, hz.Vec3.zero, hz.Quaternion.zero).then(entities => {
const hud = entities[0];
// The HUD is an AttachableEntity, so we can attach it to the player's head
hud.as(hz.AttachableEntity).attachToPlayer(player, hz.AttachablePlayerAnchor.Head);
});
}
}
else {
console.warn("PlayerManager: Player already joined world");
}
}Here is the start() method from the HUD script
start() {
console.log("BigBox_UI_ToastHud: Starting Toast HUD");
// Check if this is running on the Server or Client
const localPlayer = this.world.getLocalPlayer();
// Only attach listeners if this is running on the local player
if (localPlayer) {
this.connectNetworkBroadcastEvent(BigBox_ToastEvents.textToast, this.onLocalTextToast.bind(this));
}
}When a player joins the world, the HUD is correctely created in the world but the start() method isn't triggered (I presume since the message isn't displayed in the console and it doesn't work at all). I precise that the HUD Script is setted in local mode.
Have you any idea why ? Thank a lot for your help !
Yeah it's good ! The FBS's window says that there may be problem with assets for no visible reason and we just have to recreate it, and that's what I did and it's working now 👍
Thank you for your help I wouldn't have seen this by myself