🌴 Moonshine Objects
An extension to Bevy entities to make complex ECS hierarchies more ergonomic.
Entities are nice. Objects are better! 😎
Overview
Object provides an ergonomic interface for traversing and querying an entity hierarchy.
It is a wrapper around 3 common queries in Bevy:
Query<&Name>
Query<&Parent>
Query<&Children>
Any Entity can be expressed as an Object.
Additionally, an Object<T: Kind> provides type safety through Kinds.
An Object is not a query item itself, rather accessible via the Objects<T> system parameter:
;
Because an Object has access to hierarchy and name information, it can provide a set of useful functions, such as:
This makes it very easy to pass this information between your systems and functions:
Casting
Like Instance<T>, an Object<T> maybe be cast into an Object<U> if T implements CastObjectInto<U>. You may implement this trait for your own kinds using the safe_object_cast macro:
// We expect every Bird to have a Creature component.
// Therefore, all birds may safely be assumed to be creatures:
safe_object_cast!;
// Birds can chirp.
// Creatures can find food.
// Birds chirp when they get hungry.
Any Object<T> is safely convertible to Object.
You can define as many casts as you want. Any object kind may be cast into any other object kind as long as a safe_object_cast is defined for it.
Filters
Like a standard Query, you can filter Objects by passing a QueryFilter to the iter method:
;