Api Sandbox Component
class

Component

public abstract class Component

A GameObject can have many components, which are the building blocks of the game.

Properties

Name Type Description
Scene Scene The scene this Component is in. This is a shortcut for `GameObject.Scene`.
Transform GameTransform The transform of the GameObject this component belongs to. Components don't have their own transforms but they can access the transform of the GameObject they belong to. This is a shortcut for `GameObject.Transform`.
GameObject GameObject The GameObject this component belongs to.
Components virtual ComponentList Access components on this component's GameObject
Enabled Boolean The enable state of this Component. This doesn't tell you whether the component is actually active because its parent GameObject might be disabled. This merely tells you what the component wants to be. You should use Active to determine whether the object is truly active in the scene.
Active Boolean True if this Component is enabled, and all of its ancestor GameObjects are enabled
IsValid virtual Boolean
OnComponentEnabled Action
OnComponentStart Action
OnComponentUpdate Action
OnComponentFixedUpdate Action
OnComponentDisabled Action
OnComponentDestroy Action
Tags ITagSet
DebugOverlay DebugOverlaySystem Allows drawing of temporary debug shapes and text in the scene
Flags ComponentFlags
Id Guid
LocalTransform Transform The local transform of the game object.
LocalPosition Vector3 The local position of the game object.
LocalRotation Rotation The local rotation of the game object.
LocalScale Vector3 The local scale of the game object.
Network NetworkAccessor
IsProxy Boolean True if this is a networked object and is owned by another client. This means that we're not controlling this object, so shouldn't try to move it or anything.
ComponentVersion virtual Int32 The version of the component. Used by JsonUpgrader.
WorldTransform Transform The world transform of the game object.
WorldPosition Vector3 The world position of the game object.
WorldRotation virtual Rotation The world rotation of the game object.
WorldScale virtual Vector3 The world scale of the game object.

Methods

Void Destroy()

Destroy this component, if it isn't already destroyed. The component will be removed from its GameObject and will stop existing. You should avoid interating with the component after calling this.

Void DestroyGameObject()

Destroy the parent GameObject. This really only exists so when you're typing Destroy you realise that calling Destroy only destroys the Component - not the whole GameObject.

virtual Void Reset()
Void EditLog(String name, Object source)

Called when something on the component has been edited

Void Invoke(Single secondsDelay, Action action, CancellationToken ct = null)

Invoke a method in x seconds. Won't be invoked if the component is no longer active.

virtual Void OnParentDestroy()

The parent object is being destroyed. This is a nice place to switch to a healthier parent.

T AddComponent(Boolean startEnabled = True)

Add a component to this GameObject

T GetOrAddComponent(Boolean startEnabled = True)

Add a component to this GameObject

T GetComponent(Boolean includeDisabled = False)

Get a component on this GameObject

IEnumerable<T> GetComponents(Boolean includeDisabled = False)

Get components on this GameObject

IEnumerable<T> GetComponentsInChildren(Boolean includeDisabled = False, Boolean includeSelf = True)

Get components on this GameObject and on descendant GameObjects

T GetComponentInChildren(Boolean includeDisabled = False, Boolean includeSelf = True)

Get component on this GameObject or on descendant GameObjects

IEnumerable<T> GetComponentsInParent(Boolean includeDisabled = False, Boolean includeSelf = True)

Get components on this GameObject and on ancestor GameObjects

T GetComponentInParent(Boolean includeDisabled = False, Boolean includeSelf = True)

Get component on this GameObject and on ancestor GameObjects

JsonNode Serialize(SerializeOptions options = null)
Void Deserialize(JsonObject node)
Void DeserializeImmediately(JsonObject node)

Deserialize this component as per JsonObject) but update GameObject and Component property references immediately instead of having them deferred.

static override Object JsonRead(Utf8JsonReader reader, Type targetType)
static override Void JsonWrite(Object value, Utf8JsonWriter writer)
Assembly: Sandbox.Engine Namespace: Sandbox Full Name: Sandbox.Component