#Query<dyn Trait>?

13 messages · Page 1 of 1 (latest)

neon jewel
#

I thought this was already supported but cannot find any related code or documentation. Are traits supported in queries? Is it possible to query all components which implement a trait instead of a concrete component type?

Note: As I understand this is different from "dynamic queries" which are queries based on a type known at runtime but not at compile time. Here I know the trait type at compile time, but not all its implementations.

prisma iris
neon jewel
#

Yes I saw that, but I thought I remembered @fleet copper saying this was already supported in Bevy core, did I get confused? 🤔

fleet copper
#

We've discussed upstreaming though

#

Not a priority, but on the table

tardy cedar
neon jewel
tardy cedar
#

hmmmm that does suck. the only thing that comes up in my mind is a macro that expands into a tuple of all the types implementing the trait. but i know nothing about macros so not even sure if that's possible

#

so you'd do something like add_systems(Update, tweening!(Mytrait)) ?

weary mango
#

There are some platform specific workarounds but they all involve directly asking the linker to do things

neon jewel
#

typetag already does something like that (used in Hanabi) and that's not really what I'm asking, I'm looking for a query based on a trait, not on a hidden enum and some registration. Also the registration would be best handled in the TyprRegistry which is another discussion that has been going for some time and is not currently available.

It looks like the next best thing would actually be dynamic queries though, since in the bevy_tweening case I do have a place where I know the concrete type, and could build the associated query there.

I'll try to think about this a bit more.