Cheat Sheet
Sometimes you know what you're looking for, but you don't know where it is.
Sometimes you know what you're looking for, but you don't know where it is.
Debugging
| Name | Code |
|---|---|
| Logging to console | Log.Info( $"Hello {username}" ); |
| Drawing to screen | DebugOverlay.ScreenText( new Vector2( 50, 50 ), "Hello" ); |
| Asserting | Assert.NotNull( obj, "Object was null!" ) |
Transforms
| Name | Code |
|---|---|
| Get GameObject Position | var p = go.WorldPosition; |
| Set GameObject Position | go.WorldPosition = new Vector3( 10, 0, 0 ); |
| Get Local Position | var p = go.LocalPosition; |
GameObjects
| Name | Code |
|---|---|
| Find by name | Scene.Directory.FindByName( "Cube" ).First(); |
| Find by Guid | Scene.Directory.FindByGuid( guid ); |
| Creating | var go = new GameObject(); |
| Deleting | go.Destroy() |
| Disabling | go.Enabled = false; |
| Duplicating | var newGo = go.Clone(); |
| Adding a Tag | go.Tags.Add( "player" ); |
| Iterate Children | foreach( var child in go.Children ) |
| Deleted Check | if ( go.IsValid() ) |
Components
| Name | Code |
|---|---|
| Add component | var c = go.AddComponent<ModelRenderer>(); |
| Remove component | c.Destroy() |
| Disabling | c.Enabled = false; |
| Get GameObject | var go = c.GameObject; |
| Get Component | var c = go.GetComponent<ModelRenderer>(); |
| Get or Add | var c = go.GetOrAddComponent<ModelRenderer>(); |
| Iterate | foreach ( var c in go.Components.GetAll() ) |
| Deleted check | if ( c.IsValid() ) |
| Get all active | foreach ( var c in Scene.GetAll<CameraComponent>() ) |
Referenced API
Canonical API pages mentioned in this guide.
Vector2
A 2-dimensional vector. Typically represents a position, size, or direction in 2D space.
Vector3
A 3-dimentional vector. Typically represents a position, size, or direction in 3D space.
Facepunch.ActionGraphs.Null
Represents a null reference.
Sandbox.CameraComponent
Every scene should have at least one Camera.
Sandbox.Diagnostics.Assert
No summary available.
Sandbox.ModelRenderer
Renders a model in the world
Sandbox.Resources.ResourceCompileContext.Child
No summary available.
Sandbox.Scene
No summary available.