S&box Wiki

Creating A Game

Creating A Game

The easiest way to start creating a game is to download and rename the minimal gamemode.

You should also have an adequate coding workspace setup by following one of the following guides:

Addon directory structure

Addon folder names need to be entirely lowercase. https://github.com/Facepunch/sbox-issues/issues/710
A restart of the whole game is required after creating a new addon folder.

Every addon is self contained in its own folder in the addons directory. For example an addon called "myaddon" would be in the following path:


This folder should contain an .addon file (which is just json). This tells the game that the folder contains an addon. The .addon file doesn't need to contain anything except sharedassets otherwise your content won't be sent to clients:

{ "sharedassets": "*.*" }

After you have your .addon file you can generate your solution file and dive into coding.


All your code should be contained inside a code folder within your addon folder.


Any C# code within this folder is compiled and used for your game.


All your content can go in folders within your addon folder.

  • addons/myaddon/config - for fgd files or for defining custom asset types
  • addons/myaddon/fonts - fonts here are automatically loaded and available for usage in UI
  • addons/myaddon/maps - maps are added to the menu from here
  • addons/myaddon/materials
  • addons/myaddon/models
  • addons/myaddon/particles
  • addons/myaddon/shaders - shaders placed in here are compiled
  • addons/myaddon/sounds

Initial Game code

Every game you make needs a Game class, this is the entry point for all your game logic.

Initially you need to make sure your game class is derived from Sandbox.Game. This needs to be in a .cs file in your addon code folder, we recommend calling it Game.cs.

public partial class MyGame : Sandbox.Game { public MyGame() { } }

With this your game should now show up in the main menu and let you load into a map.

Your first pawn

When a client joins a server, by default nothing happens. You need to create a Pawn for that client to control. A Pawn is just an Entity that is controlled by a Client.

To create a first person player you can derive a new entity from the Sandbox.Player and creating it from Game.ClientJoined like so:

// MyPlayer.cs using Sandbox; partial class MyPlayer : Player { public override void Respawn() { SetModel( "models/citizen/citizen.vmdl" ); // Use WalkController for movement (you can make your own PlayerController for 100% control) Controller = new WalkController(); // Use StandardPlayerAnimator (you can make your own PlayerAnimator for 100% control) Animator = new StandardPlayerAnimator(); // Use ThirdPersonCamera (you can make your own Camera for 100% control) Camera = new ThirdPersonCamera(); EnableAllCollisions = true; EnableDrawing = true; EnableHideInFirstPerson = true; EnableShadowInFirstPerson = true; base.Respawn(); } } // Game.cs using Sandbox; public partial class MyGame : Sandbox.Game { public override void ClientJoined( Client client ) { base.ClientJoined( client ); // Create a pawn and assign it to the client. var player = new MyPlayer(); client.Pawn = player; player.Respawn(); } }


  • The Game class is an Entity like everything else, and as such can make use of networked types fully to keep clients in sync on the current game state.
  • A good way to know what you can do with the Game is to use intellisense to see what you can override.

Special Pages



Render Time: 64ms

DB GetPage 27
Generate Html 4
SaveChanges (1) 28
Render Body 0
Render Sidebar 1