Skip to content

bevy_reflect: Access Type from dyn PartialReflect#24585

Open
MrGVSV wants to merge 4 commits into
bevyengine:mainfrom
MrGVSV:mrgvsv/comptime-and-runtime-types
Open

bevy_reflect: Access Type from dyn PartialReflect#24585
MrGVSV wants to merge 4 commits into
bevyengine:mainfrom
MrGVSV:mrgvsv/comptime-and-runtime-types

Conversation

@MrGVSV

@MrGVSV MrGVSV commented Jun 10, 2026

Copy link
Copy Markdown
Member

Objective

The Type type was added in #14838 and acts like a TypeId that retains info of its TypePath. However, this was somewhat tedious to retrieve on a reflected value.

If you have a dyn Reflect, you have to do this:

value.reflect_type_info().ty()

And if all you have is a dyn PartialReflect, then you have to do this:

value.get_represented_type_info().map(TypeInfo::ty).copied()

And on top of that, this means that we can never get the Type of a dynamic type at runtime since dynamic types do not have a corresponding TypeInfo.

Compare this to TypePath, which via DynamicTypePath (a supertrait on PartialReflect), we can do this to get the type path of a dyn PartialReflect:

value.reflect_type_path()

And that will work for both dynamic and concrete types.

This should be true for Type as well.

Solution

This PR adds two new methods:

  • PartialReflect::comptime_type
  • PartialReflect::runtime_type

I chose the comptime and runtime prefixes because I wanted words that weren't as overloaded. I could have also gone with concrete and dynamic, but my worry was that dynamic_type would be too easily confused with our concept of a "dynamic type". And it's actually the opposite: this doesn't return the Type of the underlying dynamic type, but the Type of the concrete type the underlying dynamic type is proxying.

I'm open to feedback on the names!

I did try to unify the terminology to some extent by also making the following changes:

  • PartialReflect::get_represented_type_info -> PartialReflect::runtime_type_info
  • DynamicTyped::reflect_type_info -> DynamicTyped::comptime_type_info

Todo

  • Add migration note once naming is finalized

Testing

Added unit tests for remote types.


Showcase

TODO

@MrGVSV MrGVSV added C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 10, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in Reflection Jun 10, 2026
@alice-i-cecile alice-i-cecile added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide and removed D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

@alice-i-cecile

Copy link
Copy Markdown
Member

I quite like your choice of names, and the functionality is useful here :) I think we can stabilize those names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants