s&box docs

public abstract class Sandbox.Component

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

Broader workflow and conceptual references connected to this API.

Constructors

Showing 1 constructors

Methods

Showing 45 methods

protected T __sync_GetValue(Sandbox.WrappedPropertyGet`1<T> p)

protected void __sync_SetValue(Sandbox.WrappedPropertySet`1<T> p)

public T AddComponent(bool startEnabled = True)

Add a component to this GameObject

Parameters

  • startEnabled: Default: True

public void Deserialize(System.Text.Json.Nodes.JsonObject node)

public void DeserializeImmediately(System.Text.Json.Nodes.JsonObject node)

Deserialize this component as per `Sandbox.Component.Deserialize(System.Text.Json.Nodes.JsonObject)` but update `Sandbox.Component.GameObject` and `Sandbox.Component` property references immediately instead of having them deferred.

public 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.

public 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.

protected virtual void DrawGizmos()

Called in the editor to draw things like bounding boxes etc

Implementations

public void EditLog(string name, object source)Obsolete

Called when something on the component has been edited

Obsolete: EditLog is obsolete use Scene.Editor.UndoScope or Scene.Editor.AddUndo instead.

public T GetComponent(bool includeDisabled = False)

Get a component on this GameObject

Parameters

  • includeDisabled: Default: False

public T GetComponentInChildren(bool includeDisabled = False, bool includeSelf = True)

Get component on this GameObject or on descendant GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public T GetComponentInParent(bool includeDisabled = False, bool includeSelf = True)

Get component on this GameObject and on ancestor GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public System.Collections.Generic.IEnumerable`1<T> GetComponents(bool includeDisabled = False)

Get components on this GameObject

Parameters

  • includeDisabled: Default: False

public System.Collections.Generic.IEnumerable`1<T> GetComponentsInChildren(bool includeDisabled = False, bool includeSelf = True)

Get components on this GameObject and on descendant GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public System.Collections.Generic.IEnumerable`1<T> GetComponentsInParent(bool includeDisabled = False, bool includeSelf = True)

Get components on this GameObject and on ancestor GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public T GetOrAddComponent(bool startEnabled = True)

Add a component to this GameObject

Parameters

  • startEnabled: Default: True

public void Invoke(float secondsDelay, System.Action action, System.Threading.CancellationToken ct = null)

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

Parameters

  • ct: Default: null

public bool IsRunning(Sandbox.Doo doo)

Returns true if the given Doo is currently running on this component.

public static override object JsonRead(System.Text.Json.Utf8JsonReader reader, System.Type targetType)

public static override void JsonWrite(object value, System.Text.Json.Utf8JsonWriter writer)

protected virtual void OnAwake()

Called once per component

Implementations

protected virtual void OnDestroy()

Called once, when the component or gameobject is destroyed

Implementations

protected virtual void OnDirty()Obsolete

Called when the component has become dirty

Obsolete: This API member is obsolete.

Implementations

protected virtual void OnDisabled()

Implementations

protected virtual void OnEnabled()

Called after Awake or whenever the component switches to being enabled (because a gameobject hierarchy active change, or the component changed)

Implementations

protected virtual void OnFixedUpdate()

When enabled, called on a fixed interval that is determined by the Scene. This is also the fixed interval in which the physics are ticked. Time.Delta is that fixed interval.

Implementations

protected virtual void OnParentChanged(Sandbox.GameObject oldParent, Sandbox.GameObject newParent)

The parent has changed from one parent to another

Implementations

public virtual void OnParentDestroy()

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

Implementations

protected virtual void OnPreRender()

When enabled, called every frame, does not get called on a dedicated server

Implementations

protected virtual void OnRefresh()

Called immediately after being refreshed from a network snapshot.

protected virtual void OnStart()

Called once before the first Update - when enabled.

Implementations

protected virtual void OnTagsChanged()

When tags have been updated

protected virtual void OnUpdate()

When enabled, called every frame

Implementations

protected virtual void OnValidate()

Called immediately after deserializing, and when a property is changed in the editor.

Implementations

public virtual void Reset()

Implementations

public void Run(Sandbox.Doo doo, System.Action`1<Sandbox.Doo.Configure> c = null)

Parameters

  • c: Default: null

public void Stop(Sandbox.Doo doo)

Stop a specific Doo, if it's running

public void StopAll()

Stop all running Doos

Properties

Showing 29 properties

public bool Sandbox.Component.Active { get; set; }

True if this Component is enabled, and all of its ancestor GameObjects are enabled

public virtual sealed Sandbox.ComponentList Sandbox.Component.Components { get; set; }

Access components on this component's GameObject

public virtual int Sandbox.Component.ComponentVersion { get; set; }

The version of the component. Used by `Sandbox.JsonUpgrader`.

public Sandbox.DebugOverlaySystem Sandbox.Component.DebugOverlay { get; set; }

Allows drawing of temporary debug shapes and text in the scene

public bool Sandbox.Component.Enabled { get; set; }

The enable state of this `Sandbox.Component`. This doesn't tell you whether the component is actually active because its parent `Sandbox.GameObject` might be disabled. This merely tells you what the component wants to be. You should use `Sandbox.Component.Active` to determine whether the object is truly active in the scene.

public System.Guid Sandbox.Component.Id { get; set; }

public bool Sandbox.Component.IsProxy { get; set; }

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.

public virtual sealed bool Sandbox.Component.IsValid { get; set; }

public Vector3 Sandbox.Component.LocalPosition { get; set; }

The local position of the game object.

public Rotation Sandbox.Component.LocalRotation { get; set; }

The local rotation of the game object.

public Vector3 Sandbox.Component.LocalScale { get; set; }

The local scale of the game object.

public Transform Sandbox.Component.LocalTransform { get; set; }

The local transform of the game object.

public System.Action Sandbox.Component.OnComponentDestroy { get; set; }

public System.Action Sandbox.Component.OnComponentDisabled { get; set; }

public System.Action Sandbox.Component.OnComponentEnabled { get; set; }

public System.Action Sandbox.Component.OnComponentFixedUpdate { get; set; }

public System.Action Sandbox.Component.OnComponentStart { get; set; }

public System.Action Sandbox.Component.OnComponentUpdate { get; set; }

public Sandbox.Scene Sandbox.Component.Scene { get; set; }

The scene this Component is in. This is a shortcut for `GameObject.Scene`.

protected Sandbox.TaskSource Sandbox.Component.Task { get; set; }

Allow creating tasks that are automatically cancelled when the GameObject is destroyed.

public Sandbox.GameTransform Sandbox.Component.Transform { get; set; }

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`.

public Vector3 Sandbox.Component.WorldPosition { get; set; }

The world position of the game object.

public virtual sealed Rotation Sandbox.Component.WorldRotation { get; set; }

The world rotation of the game object.

public virtual sealed Vector3 Sandbox.Component.WorldScale { get; set; }

The world scale of the game object.

public Transform Sandbox.Component.WorldTransform { get; set; }

The world transform of the game object.

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.Engine
Doc IDT:Sandbox.Component

On this page

Constructorsprotected Component()Methodsprotected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, System.Object[] argumentList)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T[] argument)protected T __sync_GetValue(Sandbox.WrappedPropertyGet`1<T> p)protected System.Void __sync_SetValue(Sandbox.WrappedPropertySet`1<T> p)public T AddComponent(System.Boolean startEnabled = True)public System.Void Deserialize(System.Text.Json.Nodes.JsonObject node)public System.Void DeserializeImmediately(System.Text.Json.Nodes.JsonObject node)public System.Void Destroy()public System.Void DestroyGameObject()protected virtual System.Void DrawGizmos()public System.Void EditLog(System.String name, System.Object source)public T GetComponent(System.Boolean includeDisabled = False)public T GetComponentInChildren(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public T GetComponentInParent(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public System.Collections.Generic.IEnumerable`1<T> GetComponents(System.Boolean includeDisabled = False)public System.Collections.Generic.IEnumerable`1<T> GetComponentsInChildren(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public System.Collections.Generic.IEnumerable`1<T> GetComponentsInParent(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public T GetOrAddComponent(System.Boolean startEnabled = True)public System.Void Invoke(System.Single secondsDelay, System.Action action, System.Threading.CancellationToken ct = null)public System.Boolean IsRunning(Sandbox.Doo doo)public static override System.Object JsonRead(System.Text.Json.Utf8JsonReader reader, System.Type targetType)public static override System.Void JsonWrite(System.Object value, System.Text.Json.Utf8JsonWriter writer)protected virtual System.Void OnAwake()protected virtual System.Void OnDestroy()protected virtual System.Void OnDirty()protected virtual System.Void OnDisabled()protected virtual System.Void OnEnabled()protected virtual System.Void OnFixedUpdate()protected virtual System.Threading.Tasks.Task OnLoad()protected virtual System.Threading.Tasks.Task OnLoad(Sandbox.LoadingContext context)protected virtual System.Void OnParentChanged(Sandbox.GameObject oldParent, Sandbox.GameObject newParent)public virtual System.Void OnParentDestroy()protected virtual System.Void OnPreRender()protected System.Void OnPropertyDirty()protected System.Void OnPropertyDirty(Sandbox.WrappedPropertySet`1<T> p)protected virtual System.Void OnRefresh()protected virtual System.Void OnStart()protected virtual System.Void OnTagsChanged()protected virtual System.Void OnUpdate()protected virtual System.Void OnValidate()public virtual System.Void Reset()public System.Void Run(Sandbox.Doo doo, System.Action`1<Sandbox.Doo.Configure> c = null)public System.Text.Json.Nodes.JsonNode Serialize(Sandbox.GameObject.SerializeOptions options = null)public System.Void Stop(Sandbox.Doo doo)public System.Void StopAll()Propertiespublic System.Boolean Sandbox.Component.Active { get; set; }public virtual sealed Sandbox.ComponentList Sandbox.Component.Components { get; set; }public virtual System.Int32 Sandbox.Component.ComponentVersion { get; set; }public Sandbox.DebugOverlaySystem Sandbox.Component.DebugOverlay { get; set; }public System.Boolean Sandbox.Component.Enabled { get; set; }public Sandbox.ComponentFlags Sandbox.Component.Flags { get; set; }public Sandbox.GameObject Sandbox.Component.GameObject { get; set; }public System.Guid Sandbox.Component.Id { get; set; }public System.Boolean Sandbox.Component.IsProxy { get; set; }public virtual sealed System.Boolean Sandbox.Component.IsValid { get; set; }public Vector3 Sandbox.Component.LocalPosition { get; set; }public Rotation Sandbox.Component.LocalRotation { get; set; }public Vector3 Sandbox.Component.LocalScale { get; set; }public Transform Sandbox.Component.LocalTransform { get; set; }public Sandbox.GameObject.NetworkAccessor Sandbox.Component.Network { get; set; }public System.Action Sandbox.Component.OnComponentDestroy { get; set; }public System.Action Sandbox.Component.OnComponentDisabled { get; set; }public System.Action Sandbox.Component.OnComponentEnabled { get; set; }public System.Action Sandbox.Component.OnComponentFixedUpdate { get; set; }public System.Action Sandbox.Component.OnComponentStart { get; set; }public System.Action Sandbox.Component.OnComponentUpdate { get; set; }public Sandbox.Scene Sandbox.Component.Scene { get; set; }public Sandbox.ITagSet Sandbox.Component.Tags { get; set; }protected Sandbox.TaskSource Sandbox.Component.Task { get; set; }public Sandbox.GameTransform Sandbox.Component.Transform { get; set; }public Vector3 Sandbox.Component.WorldPosition { get; set; }public virtual sealed Rotation Sandbox.Component.WorldRotation { get; set; }public virtual sealed Vector3 Sandbox.Component.WorldScale { get; set; }public Transform Sandbox.Component.WorldTransform { get; set; }Metadata