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
        • Player 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
  • Player Data Types
  • Retrieving Player Data
  • Setting & Updating Player Data
Export as PDF
  1. SDK Guides
  2. Players

Persisted Player Data

PreviousPlayer ManagerNextPlugins

Last updated 1 month ago

Persisted Player Data was created for your game to save progress and data related to each unique player of your game that can be retrieved in the future even after they leave and rejoin your game. This is useful for things like player progression systems, lifetime stats tracking, player quest completion and unlocks, and so much more.

The Persisted Player Data system builds on top of the Persisted Data concepts and exposes a number of convenience methods for retrieving and updating player data.

Player Data Types

Any JSON compatible data can be stored for a player. Typically, the best practice is to use a single object with many arbitrary properties that reflect the data you want to track for a player for your game.

You can learn more about supported data type here:

Retrieving Player Data

You can retrieve player data by using the player.getPersistedData() method. Any instance of a player object has this available.

Here's an example of a common usage pattern of retrieving a player's data when they join a game.

startServer(world => {  
  world.on(PlayerEvent.JOINED_WORLD, async ({ player }) => {
    // ... other common init code, like spawning an entity, etc    
    
    // get player data
    const playerData = await player.getPersistedData();
    
    // do something with the playerData
  });

  // ... other code
});

Setting & Updating Player Data

Here's an example of using this.

// other code..
await player.setPersistedData({ "someData": 123 });

Similar to retrieving player data, you can set or update player data, which utilizes , using the player.setPersistedData() method. Any instance of a player object has this available.

Supported Data Types
Shallow Merging