Skip to main content

Entity

Namespace: MonineEngine.Core

An object within a Scene. Contains a List<T> to run logic and drawing, and can contain other Entities as children.

public class Entity : System.IEquatable`1[[MonineEngine.Core.Entity, MonineEngine.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]

Inheritance ObjectEntity
Implements IEquatable<Entity>
Attributes NullableContextAttribute, NullableAttribute

Properties

Name

Gets or sets the name of the Entity.

public string Name { get; set; }

Property Value

String

Parent

Gets or sets the parent that this Entity is a child of. If this value is null, the Entity is at the root of the Entity.Scene.

public Entity Parent { get; set; }

Property Value

Entity

Scene

Gets the Entity.Scene this Entity is inside.

public Scene Scene { get; }

Property Value

Scene

Enabled

Gets or sets if the Entity is enabled or not. When false, all components are disabled, and only the Transform remains active.

public bool Enabled { get; set; }

Property Value

Boolean

Active

Gets if the Entity is active or not. When false, the Entity has been destroyed, and is no longer in the scene.

public bool Active { get; internal set; }

Property Value

Boolean

Transform

Gets the Entity.Transform of the Entity.

public Transform Transform { get; internal set; }

Property Value

Transform

Children

Gets a list of other entities that have this Entity as their parent. This list is read-only.

public List<Entity> Children { get; }

Property Value

List<Entity>

GUID

Gets the unique Entity.GUID of the Entity.

public Guid GUID { get; internal set; }

Property Value

Guid

Constructors

Entity(String)

Constructs a new Entity.

public Entity(string name)

Parameters

name String
The name of the Entity.

Methods

AddComponent<T>(T)

Adds the given Component to the Entity.

public T AddComponent<T>(T component)

Type Parameters

T
The type of Component being added.

Parameters

component T
The Component to add to the Entity.

Returns

T
The newly added Component.

GetComponent<T>()

Attempts to get and return a Components of the given type attached to this Entity.

public T GetComponent<T>()

Type Parameters

T
The type of Component to look for.

Returns

T
The Component of the given type attached to the Entity. If none were found, returns null.

GetComponent<T>(T&)

Attempts to get a Component of the given type attached to this Entity.

public bool GetComponent<T>(T& result)

Type Parameters

T
The type of Component to look for.

Parameters

result T&
The result of the search. This will be set to the Component if found. If the Component was not found, it will be set to null.

Returns

Boolean
If the Component was successfully found, true. Otherwise, false.

GetComponents<T>()

Attempts to get and return all Components of the given type attached to this Entity.

public T[] GetComponents<T>()

Type Parameters

T
The type of Component to look for.

Returns

T[]
An array with all Components of the given type attached to the Entity. If none were found, returns null.

RemoveComponent<T>()

Removes a Component of the given type from the Entity, and returns if it was successful or not.

public bool RemoveComponent<T>()

Type Parameters

T
The type of Component to remove. Searches for the first component of this type.

Returns

Boolean
If the Component was successfully found and removed, true; otherwise, false.

CreateChild(String)

Creates and returns a new child Entity within this Entity.

public Entity CreateChild(string name)

Parameters

name String
The name of the child. If unspecified, defaults to "Child".

Returns

Entity
The created child.

AddChild(Entity)

Adds the given Entity to the children of this Entity. If the Entity already has a parent, it is overriden to this Entity.

public bool AddChild(Entity entity)

Parameters

entity Entity
The Entity to add as a child.

Returns

Boolean
If the Entity was successfully added as a child, true. Otherwise, false.

Exceptions

DuplicateInstanceException
The parent Entity already has a child identical to the given Entity. Entities are not allowed to have duplicate children. (LOG)

GetChild(String)

Attempts to get and return the child with the given name that's within this Entity.

public Entity GetChild(string name)

Parameters

name String

Returns

Entity
The child Entity with the given name. If no such child exists, returns null.

Exceptions

ArgumentException
No child exists with the given name. (LOG)

GetComponents()

Gets and returns all Components currently attached to this Entity.

public Component[] GetComponents()

Returns

Component[]
An array of all Components currently attached to this Entity.

Equals(Entity)

Determines whether the current Entity is the same instance as the given Entity.

public bool Equals(Entity other)

Parameters

other Entity
The other Entity to check.

Returns

Boolean
If this Entity and the other Entity are the same instance, true; otherwise, false.

Remarks:

This is calculated using Entity.GUID, and will count 2 different Entities as not equal, even if all data is identical.

Equals(Object)

Determines whether the current Entity is the same instance as the given object.

public bool Equals(object other)

Parameters

other Object
The other object to check.

Returns

Boolean
If this Entity and the other object are the same instance, true; otherwise, false.

Remarks:

This is calculated using Entity.GUID, and will count 2 different Entities as not equal, even if all data is identical.

OnEnabled()

A method called when this Entity becomes enabled.

protected void OnEnabled()

OnDisabled()

A method called when this Entity becomes disabled.

protected void OnDisabled()

OnDestroy()

A method called when this Entity is about to be destroyed.

protected internal void OnDestroy()