-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Implement Reflect for Box<dyn Reflect> #3392
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
Comments
Hi there! Never contributed before but want to give it a try. Can I help on this issue? |
Hi @franciscoaguirre, that sounds great :) Are you comfortable with the process of making PRs in general? See https://github.com/bevyengine/bevy/blob/main/CONTRIBUTING.md#contributing-code for a refresher if you need it. This should be a straightforward PR: just drop the snippet into place, and write a simple test to verify that it works as expected :) Feel free to open a draft PR (that says "Closes #3392" in its body) and then ping me for questions in that thread (or ask around in #scenes-dev on Discord). |
What is the actual use case here? This enables nested boxing, which i'd like to avoid unless absolutely necessary. |
I don't immediately remember the end user use case right now. I suspect that #3694 will help. |
IIRC someone wanted to store |
@cart this will allow to serialize structs with Currently I creating a newtype with |
For this, it feels like what we really want is better |
It looks like it can only be serialized to RON, which is not suitable for network transmission. Also |
I ran into this while trying to write a task system for my game: #[derive(Component, Reflect)]
struct MoveTask {
to: Vec3,
next_task: Box<dyn Reflect>
}
/* more tasks here ... */
#[derive(Component, Reflect)]
struct NoOpTask {
next_task: Box<dyn Reflect>
}
fn no_op_task_tick(
mut commands: Commands,
q_tasks: Query<(Entity, &NoOpTask)>
) {
for (entity, task) in &q_tasks {
commands.entity(entity).remove::<NoOpTask>();
if let Some(new_task) = task.next_task {
commands.entity().insert_reflect(new_task);
}
}
} There might be a better way of doing this, like a command for inserting a |
I have found this to be something I would have used - also for a task system. My task steps were components that I pull out of a Vec<Box> and place the active step on the task. This worked very well, but I ran into a problem when implementing save / load using bevy reflect. I had to temporarily switch to every task step being an entity (each with one component). In my case, I was basically using an Entity as a level of indirection to the dyn Reflect component I was interested in. |
What problem does this solve or what need does it fill?
Boxed Reflect trait objects should themselves be reflectable
What solution would you like?
Implement
Reflect
forBox<dyn Reflect>
.What alternative(s) have you considered?
None.
Additional context
Working snippet from @Davier:
The text was updated successfully, but these errors were encountered: