Skip to main content
This guide walks you through creating a project in the s&box editor, setting up a scene, and writing a simple C# component that runs logic every frame.

Prerequisites

You need a working s&box installation. See Installation if you haven’t set that up yet.

Create a project and scene

1

Open the editor

Launch s&box from Steam (or from the game/ folder if you built from source). You will land on the project browser.
2

Create a new game project

Click New Project and choose the Empty Game template. Give your project a name and an ident — for example mygame.shooter. The editor creates a project folder and opens the asset browser.
3

Create a scene

In the asset browser, right-click an empty area and choose Create → Scene. Name the file main.scene. Double-click the file to open it in the scene editor.
A scene file stores the hierarchy of GameObjects and their components. You can have multiple scene files in a project and load between them at runtime.
4

Add a GameObject

In the Scene panel (top-left), click the + button and choose Create Empty. Rename the new object to Spinner by double-clicking it. Select it to show its properties in the Inspector.

Write a component

Components are C# classes that inherit from Component. The engine calls lifecycle methods — OnAwake, OnStart, OnEnabled, OnUpdate, and others — automatically at the right time.
1

Create a C# file

In the asset browser, right-click and choose Create → C# Script. Name it Spinner.cs. The editor opens the file in your configured code editor.
2

Write the spinning component

Replace the file contents with the following:
using Sandbox;

public sealed class Spinner : Component
{
    /// <summary>
    /// Degrees per second to rotate around the Z axis.
    /// </summary>
    [Property] public float Speed { get; set; } = 90f;

    protected override void OnAwake()
    {
        // Called once when the component is first activated.
        Log.Info( $"Spinner awake on {GameObject.Name}" );
    }

    protected override void OnUpdate()
    {
        // Called every frame while the component is enabled.
        // Time.Delta is the elapsed time in seconds since the last frame.
        Transform.Rotation *= Rotation.FromAxis( Vector3.Up, Speed * Time.Delta );
    }
}
Key points:
  • [Property] exposes Speed as an editable field in the Inspector.
  • Transform is a shortcut for GameObject.Transform, which controls position, rotation, and scale.
  • Time.Delta is the frame delta — always multiply per-frame changes by it to keep behaviour framerate-independent.
3

Add the component to the GameObject

Save the file. The engine hot-reloads the script automatically. Back in the editor, select the Spinner GameObject, click Add Component in the Inspector, and search for Spinner. Click it to attach the component.You should see the Speed property appear in the Inspector. You can edit it without restarting.
4

Press Play

Click the Play button in the toolbar. The scene enters play mode and the Spinner object begins rotating. Press Stop to return to edit mode.
Changes you make to [Property] values in the Inspector during play mode are not saved back to the scene file. Edit them in edit mode to persist them.

Component lifecycle reference

The full set of overridable methods on Component:
MethodWhen it is called
OnAwakeOnce, when the component is first activated
OnStartOnce, before the first OnUpdate
OnEnabledEach time the component becomes active
OnUpdateEvery frame while enabled
OnFixedUpdateAt a fixed physics interval while enabled
OnPreRenderEvery frame, just before rendering (not called on dedicated server)
OnDisabledEach time the component becomes inactive
OnDestroyOnce, when the component or its GameObject is destroyed
OnValidateAfter deserializing and after property changes in the editor

Next steps

Components

Learn how components interact with GameObjects and each other.

Component lifecycle

Understand the exact order in which lifecycle methods fire.

Scenes and GameObjects

Explore the scene hierarchy, object parenting, and prefabs.

Hot reload

Edit code while the game is running and see changes applied instantly.

Build docs developers (and LLMs) love