Skip to content

Game Objects

Eldar Muradov edited this page Feb 15, 2024 · 3 revisions

Game Objects in Era Engine

Game Objects in Era Engine is a basic game entity used by the game engine. EEntity is a base class for all game objects in Era Engine.

EEntity public fields

// Is a list of childs. Represents a part of object graph
List<EEntity> Childs;

//  Is a collection of components of type EComponent
ComponentsContainer Components;

// Is a reference to parent object
EEntity? Parent;

EEntity public properties

// Is an object Id
int Id { get; init; }

// Is an object filter mask
EEntityFilter Filter { get; init; }

// Is an object name
string Name { get; init; }

// Is a property to mark an object as inited
bool IsInitialized { get; private set; }

// Is used to set object visibility
bool ActiveSelf { get; set; }

EEntity public constructors

//  Default constructor
EEntity() { ... }

// Used to set object's name and filter mask
EEntity(string name, EEntityFilter filter) { ... }

// Used to set up object's id, name and filter mask (optional)
EEntity(int id, string name, EEntityFilter filter = default) { ... }

EEntity public methods

// Used to get component from entity by it's type
T? GetComponent<T>() where T : EComponent, new() { ... }

//  Used to create component and call it's virtual InitializeComponentInternal(...) method (only for basic components like RigidbodyComponent etc.)
T CreateComponent<T>(params object[] args) where T : EComponent, new()  { ... }

//  Used to remove a component. Trigger `bool sync` is used to sync it with the game engine. Don't set it to `true` for you custom components
void RemoveComponent<T>(bool sync = false) where T : EComponent, new()  { ... }

// Used to instantiate a game ebject using it's template
static EEntity Instantiate(EEntity original, Vector3 position, Quaternion rotation, EEntity? parent = null)  { ... }

// Used to instantiate a game ebject using it's template
static EEntity Instantiate(EEntity original, EEntity? parent = null)  { ... }

// Used to copy a component by it's reference
EComponent CopyComponent(EComponent component)  { ... }

// Used to remove a child object from Childs
void RemoveChild(EEntity entity)  { ... }

// Used to release a game object manualy
void Release()  { ... }

Pipeline

// Called at the beginning of the scene simulation. Calls `void Start()` from every alive component from the ComponentsContainer field
void Start()  { ... }

// Called every frame by the game engine. Calls `void Update(float dt)` from every alive component from the ComponentsContainer field
void Update(float dt)  { ... }

EEntityFilter

struct EEntityFilter(int Id) is a record struct used to represent an entity's filter mask. If it's set to -1, game object will be released by the game engine on the next scripting reload.

Derrived types

If you want to customize you entity object you can derrive you class from EEntity and then override some logic.