public abstract class Sandbox.Component
A GameObject can have many components, which are the building blocks of the game.
Related Guides
Broader workflow and conceptual references connected to this API.
If you want a specific file/asset type to have a custom Thumbnail/Inspector Preview, you can simply create an AssetPreview. An AssetPreview initializes a SceneWorld and SceneCamera, rendering the Camera to the Preview output, so all you need to do is populate it and/or position the Camera to your liking.
There are various interfaces that can be given to components for specific purposes.
You can define upgraders for components. Useful when making a breaking change to a component such as property renaming, or new data structures.
A Component is added to a GameObject to provide functionality. This functionality can vary wildly.
In some circumstances you may want to add additional data to the network snapshot that gets sent to clients when they join a server. One example of this might be serializing and deserializing voxel world data.
You can broadcast and listen to events in your scene using interfaces.
Constructors
Showing 1 constructors
protected Component()
No results match this filter.
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: FalseincludeSelf: Default: True
public T GetComponentInParent(bool includeDisabled = False, bool includeSelf = True)
Get component on this GameObject and on ancestor GameObjects
Parameters
includeDisabled: Default: FalseincludeSelf: 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: FalseincludeSelf: 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: FalseincludeSelf: 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 System.Text.Json.Nodes.JsonNode Serialize(Sandbox.GameObject.SerializeOptions options = null)
Parameters
options: Default: null
public void Stop(Sandbox.Doo doo)
Stop a specific Doo, if it's running
public void StopAll()
Stop all running Doos
No results match this filter.
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 Sandbox.ComponentFlags Sandbox.Component.Flags { get; set; }
public Sandbox.GameObject Sandbox.Component.GameObject { get; set; }
The GameObject this component belongs to.
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 Transform Sandbox.Component.LocalTransform { get; set; }
The local transform of the game object.
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; }
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 virtual sealed Rotation Sandbox.Component.WorldRotation { get; set; }
The world rotation of the game object.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.Component |