LogoLogo
  • Get Started
  • Getting Started
    • Initial Setup
    • Create Your First Game
    • API Reference
    • Build Your First World Map
    • Multiplayer Testing
    • Use Templates & Examples
    • Styling & Assets
      • Modeling Guidelines
      • Texturing Guidelines
      • Default Assets
  • Build Faster With AI Tools
  • SDK Guides
    • Assets
    • Audio & SFX
      • Audio Manager
    • Blocks & Chunks
      • Block Types
      • Block Type Registry
      • Chunks
      • Chunk Lattice
    • Camera
    • Chat & Commands
    • Debugging
    • Entities
      • Animations
      • Block Entities
      • Colliders & Hitbox
      • Child Entities
      • Entity Controllers
        • Base Entity Controller
        • Pathfinding Entity Controller
        • DefaultPlayer Entity Controller
        • Simple Entity Controller
      • Entity Manager
      • Model Entities
      • Movement & Pathfinding
      • Player Controlled Entities
    • Events
    • Input & Controls
    • Lighting
      • Ambient Light
      • Light Manager
      • Point Lights
      • Spot Lights
      • Sun Light (Directional)
    • Mobile
    • Persisted Data
    • Players
      • Player Manager
      • Persisted Player Data
    • Plugins
    • Physics
      • Colliders
      • Collision Groups
      • Debugging
      • Gravity
      • Raycasts
      • Rigid Bodies
    • User Interface
      • Overlay UI
      • Scene UIs
      • Scene UI Manager
    • Worlds
      • Map Data Format
  • Helpful Resources
    • HYTOPIA Architecture & Platform Overview
    • Useful Third-Party Tools
Powered by GitBook
On this page
  • Accessing The PlayerManager
  • Using The PlayerManager
  • Diving Deeper
Export as PDF
  1. SDK Guides
  2. Players

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

PreviousPlayersNextPersisted Player Data

Last updated 4 months ago

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

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 .

PlayerManager API Reference here
submit a feature request here