Add `Interactable` component when loading UI through prefabs

(Abovegame) #1

Basically the topic name says it all. How do add the Interactable to the UI when loading it through prefabs ?

Here’s how does prefab code look like:

#[derive(Debug, Deserialize, Serialize, PrefabData)]
#[serde(deny_unknown_fields)]
pub enum TexturePalettePrefab {
    TexturePalette {
        ui_transform: UiTransformData<()>,
    },
    UiTextureButton {
        ui_transform: UiTransformData<()>,
        ui_image: UiImagePrefab,
        tag: TextureButtonTag,
    },
}

The UiTextureButton entities are children relative to TexturePalette. I guess when i build it i acquire that parent entity. Either there’s some way for Interactable to implement PrefabData (maybe i should create a PR) or a way to access the children of TexturePalette ?

One more way is for me to get into the middle proccess upon loading the prefab and attach manually Interactable component ?

Interestigly this doesn’t work:

world.exec(|(tex_tag, entities, mut interactables): (ReadStorage<ui::TextureButtonTag>, Entities, WriteStorage<Interactable>) | 
        {
            for (ent, _) in (&entities, &tex_tag).join() {
                println!("{:?}", interactables.insert(ent, Interactable));
            }

        });

Primarily because there are no entities with the TextureButtonTag, so it must be some magic going on with prefabs?

By the way, i noticed this problem when trying to interact with my Ui ( and the UI does show up ), also mouse_reactive is set to true for UiTrasnformData.