Player Manager

Depending on the type of game you're building, you may need to get a list of all the currently connected players, or filter through players by username or something else. This can be cumbersome to manually track yourself.

Thankfully, we have the PlayerManager that exposes ways to quickly retrieve and iterate all Players connected to your game server, get a player by username if they're connected, and more.

Accessing The PlayerManager

The PlayerManager is used as a singleton and automatically created for the singleton GameServer instance.

You can access the player manager for your game like this:

PlayerManager.instance

Using The PlayerManager

The PlayerManager exposes a number of ways to get players connected to your game server. Here's some exampels of how to use it.

// Returns an array of all currently connected
// players for the game server
PlayerManager.instance.getConnectedPlayers();

// Returns a player instance if there is a 
// currently connected player with the provided username.
// If no matching player is found, returns undefined.
PlayerManager.instance.getConnectedPlayerByUsername('someUsername');

// Returns an array of all players
// currently in the provided world.
PlayerManager.instance.getConnectedPlayersByWorld(someWorld);

Diving Deeper

The PlayerManager class is constantly evolving. You can find the latest PlayerManager API Reference here.

If there are features that we don't currently support for PlayerManager that you'd like to see added to the HYTOPIA SDK, you can submit a feature request here.

Last updated