🌴 Moonshine Object
An extension to Bevy which provides an ergonomic interface for managing complex Entity hierarchies.
Entities are nice. Objects are better! 😎
Overview
This crate is designed to provide a wrapper for some commonly used operations when working with entities in Bevy.
It is often required for various systems to be able to traverse complex entity hierarchies. This is especially true for initialization code when various components need to reference various entities within a hierarchy of entities.
For example, consider a system which reacts to a flying bird by flapping its wings:
use *;
;
;
Although, this code is intentionally verbose to show the hierarchy complexity, this crate tries to make these situations more ergonomic by introducing Object<T>.
It behaves like an Entity or Instance<T> with some extra features:
use *;
use *;
;
;
Features
- Less boilerplate when dealing with complex entity hierarchies
- Full type safety enforced through
Kindsemantics - No macros! No registration!
Usage
Objects<T>
Use Objects<T> as a system parameter to access all Object<T> instances.
This SystemParam is designed to be used like a Query:
use *;
use *;
;
Like a Query, you may also use a QueryFilter:
use *;
use *;
;
;
Internally, Objects<T> is just a thin wrapper around some common queries:
Query<Instance<T>>Query<&ChildOf>/Query<&Children>Query<&Name>
Object<T>
Each Object<T> is a reference to an Entity with type, name, and hierarchy information. This provides a convenient way to pass this data between functions:
use *;
use *;
;
;
⚠️ Unlike an Entity or Instance<T>, Object<T> has a non-static lifetime and may not be used as a Query term.
Casting
Like Instance<T>, any Object<T> may be be cast into an Object<U> if T implements CastInto<U>.
You may implement this trait for your own kinds using the kind macro:
use *;
use *;
use *;
;
;
// Every Bird is a Creature by definition:
// Therefore, all birds may safely be cast into creatures:
// Birds can chirp.
// Creatures can find food.
// Birds chirp when they get hungry.
Any Object<T> is safely convertible to Object<Any>.
Support
Please post an issue for any bugs, questions, or suggestions.
You may also contact me on the official Bevy Discord server as @Zeenobit.