Delightex Nova allows you to collaborate and play together with others through its multiplayer Experiences.
In this tutorial, you’ll learn how to create and explore your first multiplayer session step by step.
Removing unused characters
Our current game has one small issue: when a player leaves the session, their character stays behind in the scene. Let’s fix that by cleaning up unused avatars when players disconnect.
To start, remember that a player cannot remove their own character. In most multiplayer systems, the Host serves as the authority, and we’ll follow that same approach here.
Now, the Host needs to know which character belongs to which player. To do that, we’ll use custom properties. These are automatically synchronized between all players and are perfect for passing simple information, like IDs.
Here’s how it works:
First, when a player creates their character, they attach their unique player identifier to the item using a custom property:
1character.setProperty("playerId", Multiplayer.me.id);Second, the Host listens for the “player left” event and removes any characters belonging to the disconnected player:
1if (Multiplayer.isHost) {
2 Multiplayer.onPlayerLeft(player => {
3 for (let item of Scene.items.copy()) {
4 if (item.getProperty("playerId") === player.id) {
5 item.delete();
6 }
7 }
8 });
9}This ensures that whenever someone leaves the game (whether intentionally or because of a crash), their avatar is automatically removed from the scene. The result? A cleaner, more reliable multiplayer Experience that stays synchronized for everyone!
In the next lesson, we’ll use custom properties to introduce NPCs that behave consistently for every player, allowing you to create shared logic and more dynamic multiplayer interactions.