menu_bookDocumentation
s&box Cheat Sheet
s&box Cheat Sheet
Quick reference for common s&box operations.
Debugging
| Task | Code |
|---|---|
| Logging | Log.Info($"Hello {username}"); |
| Screen text | DebugOverlay.ScreenText(new Vector2(50, 50), "Hello"); |
| Assert | Assert.NotNull(obj, "Object was null!"); |
Transforms
| Task | Code |
|---|---|
| Get position | var p = go.WorldPosition; |
| Set position | go.WorldPosition = new Vector3(10, 0, 0); |
| Get local position | var p = go.LocalPosition; |
| Set rotation | go.WorldRotation = Rotation.FromYaw(90); |
GameObjects
| Task | Code |
|---|---|
| Find by name | Scene.Directory.FindByName("Cube").First(); |
| Find by GUID | Scene.Directory.FindByGuid(guid); |
| Create | var go = new GameObject(); |
| Destroy | go.Destroy(); |
| Disable | go.Enabled = false; |
| Clone | var newGo = go.Clone(); |
| Add tag | go.Tags.Add("player"); |
| Iterate children | foreach (var child in go.Children) |
| Check valid | if (go.IsValid()) |
Components
| Task | Code |
|---|---|
| Add | var c = go.Components.Create<ModelRenderer>(); |
| Remove | go.Components.Remove(c); |
| Disable | c.Enabled = false; |
| Get GameObject | var go = c.GameObject; |
| Get component | var c = go.Components.Get<ModelRenderer>(); |
| Get or add | var c = go.Components.GetOrCreate<ModelRenderer>(); |
| Get all | foreach (var c in Scene.GetAll<CameraComponent>()) |
| Check valid | if (c.IsValid()) |
Input
| Task | Code |
|---|---|
| Key held | Input.Down("jump") |
| Key pressed | Input.Pressed("attack1") |
| Analog move | Input.AnalogMove |
| Analog look | Input.AnalogLook |
Networking
| Task | Code |
|---|---|
| Check host | if (Networking.IsHost) |
| Check client | if (Networking.IsClient) |
| Network spawn | go.NetworkSpawn(); |
| Is proxy | if (IsProxy) |
Was this helpful?