-
-
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
Ensure ExtendedMaterial works with reflection (to enable bevy_egui_inspector integration) #10548
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f17f5b5
feature: Added reflect type bounds to ExtendedMaterial for bevy_egui_…
Braymatter 7093067
chore: cargo fmt
Braymatter d836023
fix: Use Reflect instead of additional traitbounds
Braymatter 90c0bcd
cleanup: Remove unnecessary trait bounds
Braymatter 7daef50
chore: fmt
Braymatter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
FromReflect
bounds here rather thanReflect
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not an expert, or even novice on bevy_reflect, but according to the compiler
FromReflect
seems to be required byTypePath
. I tried withReflect
initially, andReflect + TypePath
bounds just now andFromReflect
seems to be the thing that works.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. What's the error you're getting if you just add
TypePath
as a bound?My thought is that we ideally don't want to force reflection on types that don't want or need it (i.e. allow the user to define a
B
andE
that are not strictlyReflect
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need reflect on this otherwise we're going to need to do a weird wrapper pattern for any custom material in order to inspect it at runtime.
StandardMaterial already implements reflect, and there's an immediate use for it in the form of runtime inspection, which is really important for our debugging process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the code that's causing this error? I ask because I'm wondering if it's an issue with how we're using it rather than how the type is defined. Like, if we're registering concrete types, then there probably shouldn't be an issue. But if we're trying to make the system/plugin generic, then we probably do need these bounds added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a
register_type::<ExtendedMaterial<StandardMaterial,MyCustomMaterial>>>()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I found the problem:
Asset
requiresTypePath
, but theTypePath
impl generated by theReflect
derive has additionalFromReflect
bounds on the generic type parameters, which means thatTypePath
is only implemented whereExtendedMaterial<B, M>
isReflect
.The fix would be to opt-out of
Reflect
's automaticTypePath
implementation and derive it separately:However, this apparently reveals a bug with the
TypePath
derive. Since it reuses some of theReflect
derive logic, it actually picks up the#[reflect(type_path = false)]
attribute and just doesn't generate anything 😅.As a temporary workaround so this isn't blocked, I recommend doing something like this:
The above code should compile and not be a breaking change!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Would love for this to make it in for .12.1 -- I just pushed the suggested change