Entity

Inherits: Node

Entities represent the things in your game. It does not have any behavior or data; it does contain components and nodes which are needed for the entity. Systems provide the behavior, while Components contain the data.

Description

An entity is essentially a Node in Godot. In fact it is a base class of a Godot Node.

In the example below the Entity called TestEntity has three Components attached to it called Movable, Rotating and Energy respectively. The node called “Components” is used to keep the structure of the Entity node clean and gives a good visual representation for the developer.

_images/components.png

Properties

int id
bool enabled

Methods

void on_init ()
void on_ready ()
void on_before_add ()
void on_after_add ()
void on_before_remove ()
void on_after_remove ()
void on_enter_tree ()
void on_exit_tree ()
void add_component (Component component)
Component get_component (String name)
bool has_component (String name)
void remove_component (String name)

Property Descriptions

The internal identifier for the Entity. This is essentially the same as the Godot object id.

Lets you enable the entity by setting this to True. When an Entity is not enabled when its setting is False, it will not be included during System updates.

Method Descriptions

  • void on_init ()

The framework will make a virtual call when the Entity is initialized. Use this in place of _init().

  • void on_ready ()

The framework will make this virtual call when the Entity is ready. Use this in place of _ready().

  • void on_before_add ()

The framework will make this virtual call when the Entity immediately before it is added to the framework.

  • void on_after_add ()

The framework will make this virtual call when the Entity immediately after it has been added to the framework.

  • void on_after_remove ()

The framework will make this virtual call just after the Entity is removed from memory.

  • void on_before_remove ()

The framework will make this virtual call just before the Entity is removed from memory.

  • void on_enter_tree ()

The framework will make this virtual call when the Entity enters the Tree. Use this in place of _enter_tree().

  • void on_exit_tree ()

The framework will make this virtual call when the Entity exits the Tree. Use this in place of _exit_tree().

Adds another Component to this Entity. If the Component has already been added it will not be added again.

  • void get_component (String name)

Returns the Component based on the Name that it is given. If the Component is not found it will return null and a Warning will be logged.

Returns True if the Component name does exist for the Entity, otherwise it will return False.

Removes the Component in name. If the Component is not found it will log a Warning.