Componentclass

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

objectComponent
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public abstract class Sandbox.Component

Constructors1

Showing 1 constructors

Methods45

Showing 45 methods

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

ParameterTypeDescription
pWrappedPropertyGet<T>
Returns:T

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

ParameterTypeDescription
pWrappedPropertySet<T>
Returns:void

public T AddComponent(bool startEnabled = True)PUBLIC

Add a component to this GameObject

ParameterTypeDescription
startEnabled = Truebool
Returns:T

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

ParameterTypeDescription
nodeJsonObject
Returns:void

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

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.

ParameterTypeDescription
nodeJsonObject
Returns:void

public void Destroy()PUBLIC

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.

Returns:void

public void DestroyGameObject()PUBLIC

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.

Returns:void

protected virtual void DrawGizmos()PROTECTEDVIRTUAL

Called in the editor to draw things like bounding boxes etc

Returns:void

public void EditLog(string name, object source)PUBLICOBSOLETE

Called when something on the component has been edited

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

ParameterTypeDescription
namestring
sourceobject
Returns:void

public T GetComponent(bool includeDisabled = False)PUBLIC

Get a component on this GameObject

ParameterTypeDescription
includeDisabled = Falsebool
Returns:T

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

Get component on this GameObject or on descendant GameObjects

ParameterTypeDescription
includeDisabled = Falsebool
includeSelf = Truebool
Returns:T

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

Get component on this GameObject and on ancestor GameObjects

ParameterTypeDescription
includeDisabled = Falsebool
includeSelf = Truebool
Returns:T

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

Get components on this GameObject

ParameterTypeDescription
includeDisabled = Falsebool
Returns:IEnumerable<T>

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

Get components on this GameObject and on descendant GameObjects

ParameterTypeDescription
includeDisabled = Falsebool
includeSelf = Truebool
Returns:IEnumerable<T>

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

Get components on this GameObject and on ancestor GameObjects

ParameterTypeDescription
includeDisabled = Falsebool
includeSelf = Truebool
Returns:IEnumerable<T>

public T GetOrAddComponent(bool startEnabled = True)PUBLIC

Add a component to this GameObject

ParameterTypeDescription
startEnabled = Truebool
Returns:T

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

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

ParameterTypeDescription
secondsDelayfloat
actionAction
ct = nullCancellationToken
Returns:void

public bool IsRunningDoo(Sandbox.Doo doo)PUBLIC

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

ParameterTypeDescription
dooDoo
Returns:bool

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

ParameterTypeDescription
readerUtf8JsonReader
targetTypeType
Returns:object

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

ParameterTypeDescription
valueobject
writerUtf8JsonWriter
Returns:void

protected virtual void OnAwake()PROTECTEDVIRTUALLIFECYCLE

Called once per component

Returns:void

protected virtual void OnDestroy()PROTECTEDVIRTUALLIFECYCLE

Called once, when the component or gameobject is destroyed

Returns:void

protected virtual void OnDirty()PROTECTEDVIRTUALOBSOLETE

Called when the component has become dirty

Obsolete: This API member is obsolete.

Returns:void

protected virtual void OnDisabled()PROTECTEDVIRTUALLIFECYCLE

Returns:void

protected virtual void OnEnabled()PROTECTEDVIRTUALLIFECYCLE

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

Returns:void

protected virtual void OnFixedUpdate()PROTECTEDVIRTUALFIXED TICK

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.

Returns:void

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

The parent has changed from one parent to another

ParameterTypeDescription
oldParentGameObject
newParentGameObject
Returns:void

public virtual void OnParentDestroy()PUBLICVIRTUALLIFECYCLE

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

Returns:void

protected virtual void OnPreRender()PROTECTEDVIRTUAL

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

Returns:void

protected virtual void OnRefresh()PROTECTEDVIRTUAL

Called immediately after being refreshed from a network snapshot.

Returns:void

protected virtual void OnStart()PROTECTEDVIRTUALLIFECYCLE

Called once before the first Update - when enabled.

Returns:void

protected virtual void OnTagsChanged()PROTECTEDVIRTUAL

When tags have been updated

Returns:void

protected virtual void OnUpdate()PROTECTEDVIRTUALPER-FRAME

When enabled, called every frame

Returns:void

protected virtual void OnValidate()PROTECTEDVIRTUAL

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

Returns:void

public virtual void Reset()PUBLICVIRTUAL

Returns:void

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

ParameterTypeDescription
dooDoo
c = nullAction<Configure>
Returns:void

public void StopAllDoo()PUBLIC

Stop all running Doos

Returns:void

public void StopDoo(Sandbox.Doo doo)PUBLIC

Stop a specific Doo, if it's running

ParameterTypeDescription
dooDoo
Returns:void

Properties29

Showing 29 properties

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

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

Returns:bool

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

Access components on this component's GameObject

Returns:ComponentList

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

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

Returns:int

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

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.

Returns:bool

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

Returns:Guid

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

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.

Returns:bool

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

Returns:bool

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

The local position of the game object.

Returns:Vector3

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

The local rotation of the game object.

Returns:Rotation

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

The local scale of the game object.

Returns:Vector3

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

Returns:Action

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

Returns:Action

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

Returns:Action

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

Returns:Action

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

Returns:Action

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

Returns:Action

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

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

Returns:Scene

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

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

Returns:TaskSource

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

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

Returns:GameTransform

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

The world position of the game object.

Returns:Vector3

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

The world rotation of the game object.

Returns:Rotation

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

The world scale of the game object.

Returns:Vector3

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 IsRunningDoo(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 RunDoo(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 StopAllDoo()public System.Void StopDoo(Sandbox.Doo doo)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