Ctrl+K

Entity

Declaration

public class Strawberry.Core.Entity

Represents a game entity that can contain components, children and tags.

Inherits: Strawberry.ReferenceObject

Constructors

Entity

Initializes a new instance of the Entity class.

void Entity()

Properties

AllComponents

Gets all components attached to this entity.

List<BaseComponent> AllComponents { get }

Scene

Gets the scene that owns this entity.

Scene Scene { get }

ID

Gets or sets the identifier for this entity.

string ID { get set }

Destroyed

Gets a value indicating whether this entity has been destroyed.

bool Destroyed { get }

Tag

Gets or sets the comma-separated tags assigned to this entity. Setting this property adds tags from the comma-delimited string.

string Tag { get set }

UpdateBegan

Gets a value indicating whether the entity has started its update phase.

bool UpdateBegan { get }

Updated

Gets a value indicating whether the entity has completed its update phase.

bool Updated { get }

UpdateEnded

Gets a value indicating whether the entity has ended its update phase.

bool UpdateEnded { get }

PauseState

Gets or sets the pause state flags for this entity.

PauseStateFlags PauseState { get set }

Parent

Gets or sets the parent entity of this entity. Setting the parent updates the child collection on the old and new parents.

Entity Parent { get set }

Children

Gets the child entities owned by this entity.

EntityCollection Children { get }

Fields

Components protected

Holds the collection of components attached to this entity.

ComponentCollection Components

Methods

Initialize

Initializes the entity with an identifier and owning scene.

void Initialize(string id, Scene owner)

Parameters:

Name Type Description
id System.String The entity identifier.
owner Strawberry.Core.Scene The scene that owns the entity.

Initialize

Initializes the entity as a child of another entity.

void Initialize(string id, Entity parent)

Parameters:

Name Type Description
id System.String The entity identifier.
parent Strawberry.Core.Entity The parent entity.

Enable

Enables the entity and triggers its initialization logic.

void Enable()

Clone

Creates a clone of this entity using a new identifier.

Entity Clone(string newId)

Parameters:

Name Type Description
newId System.String The identifier for the cloned entity.

Returns: The cloned entity.

IsChildOf

Determines whether this entity is a descendant of the specified parent entity.

bool IsChildOf(Entity parent)

Parameters:

Name Type Description
parent Strawberry.Core.Entity The potential ancestor entity.

Returns: true if this entity is a child or descendant of the parent; otherwise, false.

AddComponent

Creates and adds a new component of type T to the entity.

T AddComponent<T>()

Returns: The created component instance.

Type Parameters:

  • T — The component type.

AddComponent

Adds an existing component instance to the entity.

T AddComponent<T>(T component)

Parameters:

Name Type Description
component T The component instance to add.

Returns: The added component.

Type Parameters:

  • T — The component type.

AddComponents

Adds a set of new components to the entity.

void AddComponents<T>(List<T> components)

Parameters:

Name Type Description
components System.Collections.Generic.List The list of components to add.

Type Parameters:

  • T — The component type.

GetComponent

Gets the first component of type T attached to the entity.

T GetComponent<T>()

Returns: The component instance or null if not found.

Type Parameters:

  • T — The component type.

HasComponent

Determines whether this entity contains a component of type T.

bool HasComponent<T>()

Returns: true if the component exists; otherwise, false.

Type Parameters:

  • T — The component type.

GetComponents

Gets all components of type T attached to this entity.

T[] GetComponents<T>()

Returns: An array of matching components.

Type Parameters:

  • T — The component type.

GetComponents

Gets all components attached to this entity.

BaseComponent[] GetComponents()

Returns: An array of attached components.

GetComponentIndex

Gets the index of the specified component in the entity component list.

int GetComponentIndex(BaseComponent component)

Parameters:

Name Type Description
component Strawberry.Core.BaseComponent The component to locate.

Returns: The zero-based index, or -1 if not found.

SetComponentIndex

Sets the index of the specified component in the entity component list.

void SetComponentIndex(BaseComponent component, int index)

Parameters:

Name Type Description
component Strawberry.Core.BaseComponent The component to reposition.
index System.Int32 The new index position.

RemoveComponent

Removes the first component of type T from the entity.

void RemoveComponent<T>()

Type Parameters:

  • T — The component type to remove.

RemoveComponent

Removes the specified component instance from the entity.

void RemoveComponent(BaseComponent component)

Parameters:

Name Type Description
component Strawberry.Core.BaseComponent The component instance to remove.

ClearComponents

Removes and destroys all components attached to the entity.

void ClearComponents()

Destroy override

Destroys the entity and all of its children.

void Destroy()

AddTag

Adds a tag to this entity.

void AddTag(string tag)

Parameters:

Name Type Description
tag System.String The tag to add.

RemoveTag

Removes a tag from this entity.

void RemoveTag(string tag)

Parameters:

Name Type Description
tag System.String The tag to remove.

HasTag

Checks whether this entity contains the specified tag.

bool HasTag(string tag)

Parameters:

Name Type Description
tag System.String The tag to check.

Returns: true if the entity has the tag; otherwise, false.

OnInitialize virtual

Initializes the entity and triggers component startup callbacks.

void OnInitialize(string id, Scene owner)

Parameters:

Name Type Description
id System.String The entity identifier.
owner Strawberry.Core.Scene The owning scene.

OnDestroy

Handles entity cleanup by invoking disable and finish callbacks on attached components.

void OnDestroy()

OnBeginUpdate

Performs the beginning of the update cycle for this entity and its children.

void OnBeginUpdate()

OnEndUpdate

Performs the end of the update cycle for this entity and its children.

void OnEndUpdate()

OnUpdate

Updates this entity and its children during the update cycle.

void OnUpdate()

OnFixedUpdate

Performs fixed-step updates for this entity and its children.

void OnFixedUpdate()

OnRender

Renders this entity and its children.

void OnRender()