World

The World is the entry point for interacting with Bevy. It is provided to scripts under either the world or World static variable.

get_type_by_name

Arguments:

ArgumentTypeDescription
type_nameStringThe name of the type to get, this can be either the short type name, i.e. my_type or the long name i.e. my_crate::my_module::my_type

Returns:

ReturnDescription
Option<ScriptTypeRegistration>The type if it exists, otherwise None
MyType = world.get_type_by_name("MyType")
if MyType == nil then
    print("MyType not found")
end

get_component

Arguments:

ArgumentTypeDescription
entityEntityThe entity to get the component from
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the component

Returns:

ReturnDescription
Option<ReflectReference>The reference to the component if it exists, otherwise None
local component = world.get_component(entity, MyType)
if component ~= nil then
    print("found component:" .. component)
end

has_component

Arguments:

ArgumentTypeDescription
entityEntityThe entity to check the component for
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the component

Returns:

ReturnDescription
booltrue if the entity has the component, otherwise false
if world.has_component(entity, MyType) then
    print("Entity has MyType")
end

remove_component

Arguments:

ArgumentTypeDescription
entityEntityThe entity to remove the component from
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the component
world.remove_component(entity, MyType)

get_resource

Arguments:

ArgumentTypeDescription
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the resource

Returns:

ReturnDescription
Option<ReflectReference>The resource if it exists, otherwise None
local resource = world.get_resource(MyType)
if resource ~= nil then
    print("found resource:" .. resource)
end

has_resource

Arguments:

ArgumentTypeDescription
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the resource

Returns:

ReturnDescription
booltrue if the resource exists, otherwise false
local hasResource = world.has_resource(MyType)

remove_resource

Arguments:

ArgumentTypeDescription
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the resource
world.remove_resource(MyType)

add_default_component

Arguments:

ArgumentTypeDescription
entityEntityThe entity to add the component to
registrationScriptTypeRegistrationThe type registration as returned by get_type_by_name of the component
world.add_default_component(entity, MyType)

spawn

Returns:

ReturnDescription
EntityThe spawned entity
local entity = world.spawn()

insert_children

Arguments:

ArgumentTypeDescription
entityEntityThe parent entity
indexusizeThe index to insert the children at
childrenVec<Entity>The children entities to insert
world.insert_children(parent, 1, {child1, child2})

push_children

Arguments:

ArgumentTypeDescription
entityEntityThe parent entity
childrenVec<Entity>The children entities to push
world.push_children(parent, {child1, child2})

get_children

Arguments:

ArgumentTypeDescription
entityEntityThe parent entity

Returns:

ReturnDescription
Vec<Entity>The children entities
local children = world.get_children(parent)
for _, child in pairs(children) do
    print("child: " .. child)
end

get_parent

Arguments:

ArgumentTypeDescription
entityEntityThe child entity

Returns:

ReturnDescription
Option<Entity>The parent entity if it exists, otherwise None
local parent = world.get_parent(child)
if parent ~= nil then
    print("parent: " .. parent)
end

despawn

Arguments:

ArgumentTypeDescription
entityEntityThe entity to despawn
world.despawn(entity)

despawn_descendants

Arguments:

ArgumentTypeDescription
entityEntityThe entity to despawn descendants of
world.despawn_descendants(entity)

despawn_recursive

Arguments:

ArgumentTypeDescription
entityEntityThe entity to despawn recursively
world.despawn_recursive(entity)

has_entity

Arguments:

ArgumentTypeDescription
entityEntityThe entity to check

Returns:

ReturnDescription
booltrue if the entity exists, otherwise false
local exists = world.has_entity(entity)
if exists then
    print("entity exists")
end

query

Returns:

ReturnDescription
ScriptQueryBuilderThe query builder
local queryBuilder = world.query()

exit

Send the exit signal to the application, will gracefully shutdown the application.

world.exit()