-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
replace FromWorld with FromReflect in ReflectComponent, ReflectResource
#6060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
replace FromWorld with FromReflect in ReflectComponent, ReflectResource
#6060
Conversation
0fdac0c to
cce6f18
Compare
|
Rebased and fixed review comments |
|
This now fails because the Line 49 in fe7ebd4
@MrGVSV any thoughts on this? If scene loading should be able to provide defaults with world access, I feel like that shouldn't go through |
Hm, this is something I've been wondering myself actually. There's not a great workaround I found to allow this. Maybe using something like #6055 to generalize on |
# Objective - it would be useful to inspect these structs using reflection ## Solution - derive and register reflect - Note that `#[reflect(Component)]` requires `Default` (or `FromWorld`) until #6060, so I implemented `Default` for `Tonemapping` with `is_enabled: false`
|
I have a situation where there is no suitable implementation of Default or FromWorld for my component. I am working on Bevy's IK system which needs to store a reference to another entity to use as an IK target. I need to be able to have this component get inserted at runtime into a scene representing a character so that you can spawn characters with their IK system, but the type registry requires that either FromWorld or Default be implemented in this scenario even though I am only inserting it with all of its fields explicitly specified. I can make it an Option for now, but you shouldn't have an IK without a target, it will simply not do anything. The appropriate way to enable/disable it would be to change the number of iterations to 0, not removing its target. The IK target should also be an entity instead of storing a transform inside of the IkJoint so that you can manipulate the target itself with another target or a hierarchy, riggers do this quite often. |
# Objective - it would be useful to inspect these structs using reflection ## Solution - derive and register reflect - Note that `#[reflect(Component)]` requires `Default` (or `FromWorld`) until bevyengine#6060, so I implemented `Default` for `Tonemapping` with `is_enabled: false`
|
Superseded by #9623 |
Objective
There should be no need for components and resources to implement
FromWorldjust for accessing and inserting them into the world.Solution
T: FromWorldandlet component = T::from_world(world); component.apply(value);withT: FromReflectandlet component = T::from_reflect(value);Changelog
FromReflectinstead ofFromWorldfor#[reflect(Component)]and#[reflect(Resource)]Migration Guide
If you used
#[reflect(Component)]or#[reflect(Resource)]you now need a#[derive(FromReflect)]as well, but theFromWorld(orDefault) impl can go away.