makspll / bevy_mod_scripting

Bevy Scripting Plugin
Apache License 2.0
390 stars 31 forks source link

Indexing the `Children` component always yields `nil` #121

Closed Joakker closed 4 months ago

Joakker commented 4 months ago

In a script like the following

function Example()
    local children_t = world:get_type_by_name 'Children'
    local children = world:get_component(entity, children_t)

    print(chilren) -- Prints `Children([...])`

    print(children[1]) -- Prints `nil`
end

Even if the Children component is not empty, trying to get the nth child via the proxy reference always yields nil instead

makspll commented 4 months ago

This is because Children is a component containing a private smallvec, indexing into the component itself is not a defined operation, the current wrapper does not define an index or new index metamethod (none of the wrappers apart from glam types do)

makspll commented 4 months ago

However, the world userdata does define get_children and similar functions

Joakker commented 4 months ago

Thank you