-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Opt-out component reflection #2968
Comments
I don't think this is quite the logic we want; we both can't detect that, and don't want to require that every single component implements Instead, I think it should be opt out with an attribute at the derive site. Additionally, a better way (imo) to handle this registration would be to add a method to This does also raise an interesting question about how coupled We could avoid this by making the method on component just be a generic |
I think this deserves a bit more investigation. There are a lot of interesting and non-obvious use cases enabled by reflection. Many of those will both be more ergonomic and faster (no branching!) if we have strong guarantees. However, the existing reflection is too frustrating and limited to really have a sense of how widely we can use it.
I think that we could bypass that particular panic with a more structured approach: see #1255 and bevyengine/rfcs#33. Decoupling plus a generic |
By don't want to require that every component implements reflect, I mean in terms of components which inherently cannot implement reflect, such as (We'd expect the window to get rehydrated based on the fact that it has a I hate calling back to the windows as entities examples when I haven't gotten around to implementing it |
So for this, we already have ignorable fields in reflection. Wouldn't this just be the case of a reflected component with no non-ignored fields? |
What problem does this solve or what need does it fill?
Currently, registering components for reflection is tedious and error-prone.
This makes use cases where you want to serialize many different component types (such as game saving, scenes or networking) very frustrating to use.
As you can see in the reflection example, users must manually register every type they wish to reflect.
What solution would you like?
Now that #2254 is in place, make Reflect an additional trait bound on Component. Automatically derive Reflect for components, unless there is an existing manual impl for them.
When components are first added to the app, automatically register them.
What alternative(s) have you considered?
Other strategies for automatically registering components may exist, and may allow us to create a more complete list before the app begins (rather than causing spiky work during the game).
Some components may not have any validly reflected values; perhaps these should simply not implement
Reflect
?The text was updated successfully, but these errors were encountered: