Closed mrDIMAS closed 2 years ago
@toyboot4e, your excellent proc-macro skills can be very useful here 🙏
Thank you for calling me! I will do it today.
By the way, DirectlyInheritableEntity
might want to return slices (&[&dyn Trait]
and &mut [&mut dyn Trait]
). I'd first make a Vec
version and let's change when slices turned out to be better.
Yeah, it probably can be changed to returns a slice, I can't remember why I made it return a Vec 🤔 .
Oh, cannot return reference to temporary value
. Maybe Vec<T> vs Box<[T]>
is the proper question. And Vec<T>
looks better in that case!
Property inheritance is a mechanism, that allows you to inherit property values from base scene (or transitively, through chain of scenes). For example you have
SceneA
prefab withObjectA
inside, whileObjectA
havefoo
property. Then you create another scene and instantiateSceneA
there. Now you have a copy ofObjectA
, let's call itObjectA*
. It now have the same value offoo
property. Then you changefoo
property inObjectA
onSceneA
to some other value. The engine then will take this new value and set it tofoo
property ofObjectA*
. This will happen all the time you load a scene with instances, but if you changefoo
value inObjectA*
, it will remain unchanged. More info can be found hereTo track changes in properties, the engine uses
TemplateVariable
wrapper struct which adds flags storage to the property it wraps. When you change a property wrapped inTemplateVariable
, it automatically marks value as modified. This information is then used to fetch values from base properties.The engine uses a list of
TemplateVariable
s that is provided byDirectlyInheritableEntity
trait. Implementing this trait involves some boilerplate code, that can be easily generated by proc macro. Currently, to reduce amount of boilerplate code, the engine offsersimpl_directly_inheritable_entity_trait
macro. An example of its usage can be found hereI propose to create a
Inherit
proc-macro, that will generate similar implementation thatimpl_directly_inheritable_entity_trait
does. It should include only fields that explicitly marked with#[inherit]
macro.A simple code example: