Table of Contents

Extensions

Extensions primarily useful for code-only projects.

In a Game Studio project the editor hands you a scene, a camera, lighting and a graphics compositor before you write a line of code. Code-only starts from nothing, so these methods build the same pieces from C#. They are ordinary extension methods - a Game Studio project can call any of them - but this is the set you are most likely to reach for when there is no editor.

Extensions that apply equally either way live under the Extensions section of the manual: Animation, Camera, Entity, Game, Model, Physics, Script and Script System.

Starting the game

  • Run() - Starts the game loop. start runs once the root scene exists, update runs every frame after it.
  • Run() with async start - The same, with a start that can await between steps. update begins only once that task completes.
  • UseGameSettings() - The GameSettings asset a code-only project does not have, built in code: HRTF, physics and navigation defaults, Bepu simulations, rendering settings, shader compilation mode. Before Run(). Only needed when one of those must change - without it every subsystem runs on the same defaults a new Game Studio project ships with. In a project that does have the asset, the asset wins and the call only adds the configurations the asset lacks.

Setting up a scene

The setup is data that Run applies before start: one object instead of assembling the pieces below by hand, and one property to change one thing. Every property and piece is on the Scene Setup page.

  • Run(setup, start, update) - Applies the setup, then runs start and update. game.Run(start:) with no setup applies SceneSetup3D.Default; SceneSetup.None applies nothing.
  • SceneSetup3D - A forward compositor with the UI stage, a perspective camera with its controller, a directional light, a gradient sky and a ground plane. Camera, Lighting, Skybox and Ground each take null to leave that piece out; ClearColor, Msaa, PostEffects, GameSettings, DebugOverlay, Profiler and Instancing are the rest.
  • SceneSetup2D - The 2D equivalent: an orthographic camera with the 2D controller and a flat ground, no lights and no sky, and no tone map, so flat colours stay as written.
  • CameraSetup, LightingSetup, GroundSetup, SkyboxSetupBase - The pieces, each built through a factory: CameraSetup.Perspective(position, rotation).WithController(), LightingSetup.Studio(), GroundSetup.Visual(), new GradientSkyboxSetup().
  • UseBepu() and UseBullet(), from the physics packages, choose the physics engine; UseSkybox(), from the skyboxes package, swaps the gradient sky for the photographed one; UseInstancing(), from Stride.CommunityToolkit.Rendering.Instancing, puts the instancing render feature in the compositor. See Physics Extensions.
game.Run(new SceneSetup3D { Lighting = LightingSetup.Studio(), Ground = null }.UseBepu().UseSkybox(), start: Start);

Building a scene piece by piece

  • AddGraphicsCompositor() - Adds a default GraphicsCompositor. Nothing renders without one.
  • AddDirectionalLight() - Adds a directional light, with shadows on by default.
  • AddSkybox() - Adds a skybox, which also provides ambient lighting.
  • Add2DGround() - Adds a flat 2D ground, with a static collider from the physics engine the setup chose.
  • Add3DGround() - Adds a ground plane, with a static collider from the physics engine the setup chose.
  • AddInfinite3DGround() - Adds a ground plane that nothing can fall off. Bullet only.
Note

The grounds and CreatePrimitive attach the collider of whichever physics engine the setup chose with UseBepu() or UseBullet(); with neither, they add the mesh alone. Each package's entity extensions (AddBepuPhysics(), AddBulletPhysics()) attach its physics explicitly, whatever the setup chose.

Cameras

  • Add2DCamera() - Adds a 2D camera and binds it to the compositor's first camera slot.
  • Add3DCamera() - Adds a 3D camera, perspective by default.
  • Add2DCameraController() - Makes the 2D camera pannable and zoomable, with an on-screen key reminder toggled by F2.
  • Add3DCameraController() - Adds free-look movement to the 3D camera. The F2 panel also prints the camera's live position and rotation, which is the quickest way to find numbers worth hard-coding.
  • See Camera Controllers for the keys, the on-screen help and every option on both scripts.
  • GrabberScript - On the camera entity too, through game.AddGrabber(): left mouse picks up any dynamic body, carries it, and throws it on release, through servo constraints so the body still collides.
  • Grabber2DScript - The same for a Box2D world: give it the Box2DSimulation and the left mouse picks up, drags and throws through a kinematic anchor and a motor joint.
  • CharacterMover2D - A platformer character for a Box2D world with no rigid body: a capsule moved Quake style on Box2D v3's mover API, registered with the simulation, driven by Throttle and Jump().
  • SetCameraPosition() - Moves the existing camera. Use this after the setup rather than calling Add3DCamera() again, which would create a second camera competing for the same slot.
  • SetCameraRotation() - Aims the existing camera, taking yaw, pitch and roll in degrees.

Sound

A code-only game has no Sound asset, so these are the only way to make a noise. All on game.Audio, from the start callback onwards; see Audio Extensions for the rest.

  • CreateProceduralSound() - A sound generated by a callback, with no file behind it.
  • LoadWav() - Reads a .wav from disk into a WavSound; each CreateInstance() is an independent playback.
  • AttachListener() - A listener that follows the camera, for spatialised sound. The engine's default listener never moves.

Rendering and debugging

  • ConfigurePostEffects() - Turns post effects on: fx.Bloom.Enabled = true. Everything starts disabled, and the colour transforms other than tone mapping must be added rather than enabled. Call it after AddCleanUIStage().
  • SetDeterministic() - Pins the loop so frame N is the same simulated instant on every run: fixed timestep, draws in step, one update per draw. For replays, lockstep, tests and screenshots.
  • AddCleanUIStage() - Adds a UI render stage to the GraphicsCompositor and resets its post effects to tone mapping only, so UI text stays clean and white. Enable bloom or other effects after this call.
  • AddRenderTextureCamera() - Makes a camera draw into a texture alongside the main view, for mirrors, monitors and minimaps; see Render to Texture.
  • AddGpuPicker() - Answers what is under a screen point from the rendered frame, with no collider: entity, mesh, material, instance and surface point, two frames after the request; see GPU Picking. In the Stride.CommunityToolkit.Effects package.
  • AddDebugShapes() - Registers the immediate-mode debug shape renderer, for drawing lines, spheres and boxes each frame.