S&box Wiki


What is a Pawn

A Pawn is an Entity any Client (player) can possess, this is the physical representation of your player within the world. This entity doesn't need to be anything specific, you can make it a physics object or a traditional animated player.

When a Client possesses a Pawn additional methods become active on the Entity:

Setting a Client's Pawn

You can set the Client's Pawn at any point, a standard place to set it would be when the client first joins.

/// <summary> /// A client has joined the server. Make them a pawn to play with /// </summary> public override void ClientJoined( Client client ) { base.ClientJoined( client ); var player = new MinimalPlayer(); client.Pawn = player; player.Respawn(); }

Accessing Pawns

A good way to get all pawns in the game is to iterate through all clients and access their pawns:

// Loop through every Client (remember, these are our pawn owners) foreach ( var client in Client.All ) { // Always check if the pawn is assigned and the correct type if ( client.Pawn is not MyPawn pawn ) continue; pawn.Respawn(); }

Any time you want to access your pawn clientside you can do so through Game.LocalPawn:

public class MyHealth : Panel { Label healthLabel; // blah blah public override void Tick() { healthLabel.Text = $"Health: {Game.LocalPawn.Health}"; } }