#How do you show custom assets in bevy inspector?

24 messages · Page 1 of 1 (latest)

dull cairn
#

I have the following asset:

#[derive(Debug, Deserialize, Clone, TypeUuid, TypePath)]
#[uuid = "5c97b24f-a49b-423f-9f9e-eaa19ab94027"]
pub struct StatsAsset {
    pub health: u32,
    pub attack: u32,
    pub defense: u32,
}

It's used by Character:

#[derive(Bundle, Default)]
pub struct CharacterBundle {
    // Main components
    pub name: Name,
    pub movable: Movable,
    pub sheet: SpriteSheetBundle,
    pub animation_indices: AnimationIndices,
    pub animation_timer: AnimationTimer,

    // Stats components
    pub stats: Handle<StatsAsset>,
#

Do you think I could convert that asset into specific components for each field if that isn't feasible? (e.g. Health, Defense, etc.)

noble pike
#

something smells off here

#

my first instinct would be to just load in the asset and set them as separate components per character

#

what is the reason behind putting those stats into an asset?

#

if they aren't expanded into several components later, then it seems weird that you'd put attack in the same component as health

noble pike
#

for more reasons than just the inspector

dull cairn
dull cairn
noble pike
#

hm

#

can you have a system that detects when a handle is hot reloaded

#

that way, if the handle is hot reloaded it can just automatically apply changes to its components

#
fn set_stats(
    handles: Query<
        (&mut Health, &mut Attack, &mut Defense, &Handle<StatsAsset>),
        AssetEvent<StatsAsset>,
    >,
) {
    // ...
}
noble pike
dull cairn
noble pike
#

listen to AssetEvent::Modified too

dull cairn
noble pike
#

there are 3 types of events

#
pub enum AssetEvent<T>
where
    T: Asset,
{
    Created {
        handle: Handle<T>,
    },
    Modified {
        handle: Handle<T>,
    },
    Removed {
        handle: Handle<T>,
    },
}
dull cairn
#

yeah, I guess I'll be using only Created and Modified in this context

#

btw, I see why using components is useful in this case. Assets are unique just like Resources right? It means I cannot use it for properties that should change across time (like health, for example)