Skip to content

What's the best practise for type distribution? #17839

Answered by Rratic
Rratic asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a solution using reflect.

Defining the struct that saves type-id:

/// Trait for implementing how a game object works.
#[reflect_trait]
pub trait Object {
    // ...
}

/// Added when the entity is a game object.
#[derive(Component, Clone)]
pub struct IsObject(pub TypeId);

impl IsObject {
    pub fn spawn_attach_image(
        &self,
        world: &World,
        ec: &mut EntityCommands,
        entity: Entity,
        rpg_folder: &Res<RpgTextures>,
        type_registry: &AppTypeRegistry,
    ) {
        let x = world.get_reflect(entity, self.0).unwrap();
        let binding = type_registry.0.read();
        let r = binding.get_type_data::<ReflectObject>(self.0).unwrap();
        

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Rratic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant