-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Allow Custom Implementations of ReflectComponent
#6206
Comments
@MrGVSV and @jakobhellermann, pinging you just in case you have thoughts. |
I'd be fine to either make these fields public, or add a constructor method. I suspect the latter will be safer, as it avoids accidentally mutating the fields of pre-existing |
I think your use case makes sense and it feels like reflection should allow doing dangerous things like overwriting a I agree with @alice-i-cecile that it would be best to protect those fields from unsuspecting users. A constructor would be good but there's a lot of fields to set. Maybe we should use a builder pattern? Or pass a config object? Also would you need to do the same sort of thing for |
I can't tell immediately whether assigning to those fields could cause undefined behavior, unless of course it was the Also, users of In other words I think it'd be highly unlikely to modify one on accident, but I'm not really against a constructor either way.
If we did it, I think I'd prefer a config object. There aren't a lot of builders in the Bevy API so far, at least as far as I've used. I guess the config object would literally be an identical struct, but with all the fields public. Then you'd pass that into a
Yes, actually. I hadn't thought of resources yet, but its the same scenario. |
# Objective - Fixes bevyengine#6206 ## Solution - Create a constructor for creating `ReflectComponent` and `ReflectResource` --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section. ### Added - Created constructors for `ReflectComponent` and `ReflectResource`, allowing for advanced scripting use-cases.
# Objective - Fixes bevyengine#6206 ## Solution - Create a constructor for creating `ReflectComponent` and `ReflectResource` --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section. ### Added - Created constructors for `ReflectComponent` and `ReflectResource`, allowing for advanced scripting use-cases.
# Objective - Fixes bevyengine#6206 ## Solution - Create a constructor for creating `ReflectComponent` and `ReflectResource` --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section. ### Added - Created constructors for `ReflectComponent` and `ReflectResource`, allowing for advanced scripting use-cases.
# Objective - Fixes bevyengine#6206 ## Solution - Create a constructor for creating `ReflectComponent` and `ReflectResource` --- ## Changelog > This section is optional. If this was a trivial fix, or has no externally-visible impact, you can delete this section. ### Added - Created constructors for `ReflectComponent` and `ReflectResource`, allowing for advanced scripting use-cases.
What problem does this solve or what need does it fill?
While working on a scripting interface to Bevy I've run into the use-case to provide a custom implementation of
ReflectComponent
for a customReflect
type.Essentially the custom
Reflect
type is aJsComponent
type that could represent any number of differentComponentId
s, though they are all backed by the same Rust type. TheJsComponent
type stores theComponentId
of the component that it represents internally, and this requires a custom implementation ofReflectComponent
to allow the component to be inserted with the proper component ID when adding it to the Bevy world.Unfortunately, I can't make a custom implementation of
ReflectComponent
, because it's fields are private.What solution would you like?
This is largely a question, but do you think it would make sense to make the fields of
ReflectComponent
public, to allow custom implementations?What alternative(s) have you considered?
The alternative I can imagine is that I just create a
CustomReflectComponent
type data that I check for instead ofReflectComponent
, but that is more intrusive. In my current use-case, that requires hard-coding support for my custom component type into thebevy_mod_js_scripting
scripting interface, instead of having my custom component transparently supported along with all the other components, simply by overriding theReflectComponent
implementation.Additional context
None.
The text was updated successfully, but these errors were encountered: