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.startruns once the root scene exists,updateruns every frame after it.Run()with asyncstart- The same, with astartthat canawaitbetween steps.updatebegins only once that task completes.UseGameSettings()- TheGameSettingsasset a code-only project does not have, built in code: HRTF, physics and navigation defaults, Bepu simulations, rendering settings, shader compilation mode. BeforeRun(). 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 runsstartandupdate.game.Run(start:)with no setup appliesSceneSetup3D.Default;SceneSetup.Noneapplies 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,SkyboxandGroundeach takenullto leave that piece out;ClearColor,Msaa,PostEffects,GameSettings,DebugOverlay,ProfilerandInstancingare 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()andUseBullet(), from the physics packages, choose the physics engine;UseSkybox(), from the skyboxes package, swaps the gradient sky for the photographed one;UseInstancing(), fromStride.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 defaultGraphicsCompositor. 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, throughgame.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 theBox2DSimulationand 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 byThrottleandJump().SetCameraPosition()- Moves the existing camera. Use this after the setup rather than callingAdd3DCamera()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.wavfrom disk into aWavSound; eachCreateInstance()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 afterAddCleanUIStage().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 theGraphicsCompositorand 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 theStride.CommunityToolkit.Effectspackage.AddDebugShapes()- Registers the immediate-mode debug shape renderer, for drawing lines, spheres and boxes each frame.