World¶
Extends EngineObject.
Create one with World.new().
Properties¶
delta_time: numberThe time step of the current Progress; what systems read for their delta time. Read-only.frame: numberThe number of frames Progress has run. Read-only.
Methods¶
create_entity¶
function create_entity(self, name: string?, parent: Entity?): Entity
A new entity; with a name, the entity of that name (created when it does not exist). A parent makes the name relative to it.
is_alive¶
function is_alive(self, entity: Entity): boolean
destroy¶
function destroy(self, entity: Entity): ()
Deletes the entity with its components; its id is never alive again, even when Flecs reuses the number.
lookup¶
function lookup(self, path: string): Entity
Finds an entity by name or path ("parent.child"); the null entity (id 0, which scripts see as the number 0) when there is none.
get_name¶
function get_name(self, entity: Entity): string?
The entity's name, or null when it has none or is not alive (Flecs does not check, and a dead entity's memory is gone).
set_name¶
function set_name(self, entity: Entity, name: string): ()
get_parent¶
function get_parent(self, entity: Entity): Entity
add¶
function add(self, entity: Entity, id: Entity): ()
remove¶
function remove(self, entity: Entity, id: Entity): ()
has¶
function has(self, entity: Entity, id: Entity): boolean
progress¶
function progress(self, deltaTime: number): ()
Runs the systems of one frame in their phases. A system or observer that throws does not stop the others: the exceptions are collected and thrown together when the frame is done (a single one as itself, several as an AggregateException).
children¶
function children(self, parent: Entity): { Entity }
The children of an entity in creation order (the order of their ids), user entities only.
roots¶
function roots(self): { Entity }
The user entities that have no parent, in creation order.
instantiate¶
function instantiate(self, reference: string, parent: Entity?): Entity
Makes the entities of a prefab file under parent (the world's top level when none) and returns the root, which has PrefabInstance; every entity made has PrefabMember with its id in the file. The entities are plain: the file's components are copied, and changing the instance changes nothing in the file. From a script this reads without the per-mod confinement of fs.read_text, as load_scene_file does.
prefab_of¶
function prefab_of(self, entity: Entity): string?
The prefab an instance root was made from, as the text of its AssetRef (res://prefabs/lamp.aprefab|uid://…); null for any other entity.
save_scene¶
function save_scene(self): string
The user entities (IsUserEntity) as scene text (XML). It has no uid: text is a copy, and a copy must not carry the identity of a file.
load_scene¶
function load_scene(self, text: string, parent: Entity?): { Entity }
Creates the entities of scene text, under parent when given, and returns them in the order of the file (parents first). A component the file names that this world cannot find, and a field it does not have, are logged and skipped; components that scripts defined are defined again from the file. Throws FormatException when the text is not a scene.
load_scene_file¶
function load_scene_file(self, path: string, parent: Entity?): { Entity }
Creates the entities of the scene file at path (a path, or uid://… for the file that has that UID, wherever it moved to), under parent when given. The file is read as XmlFile reads it, so a scene cooked into a pack loads like the text one. From a script this reads without the per-mod confinement of fs.read_text, as models.load and ui:load_document do. See LoadScene(string, Entity).
component¶
function component(self, name: string, fields: ({ [string]: FieldType } | {})?): number
set¶
function set(self, entity: number, component: number, values: { [string]: any }?): ()
get¶
function get(self, entity: number, component: number): { [string]: any }?
count¶
function count(self, components: { Term }): number
each¶
function each(self, components: { Term }, callback: (entity: number, ...ComponentView) -> ()): ()
system¶
function system(self, name: string, components: { Term }, callback: (entity: number, ...ComponentView) -> (), phase: Phase?): number