Issue with loading SpriteScenePrefab from several files

(Sergey Veselkov) #1

During prefab loading SpriteScenePrefab adds SpriteSheetHandle in to SpriteSheetLoadedSet.

If you load several prefabs from different files, the sequence of adding SpriteSheetHandle to SpriteSheetLoadedSet is not defined and you cannot specify a sheet index for SpriteRenderPrefab.

for path in prefab_paths {
        let handle = world.exec(|loader: PrefabLoader<GamePrefab>| {
        loader.load(path, RonFormat, (), &self.progress)

I think we can change the Vec<SpriteSheetHandle> to the HashMap<String,SpriteSheetHandle> in SpriteSheetLoadedSet and add a String field to the SpriteSheetPrefab as an identifier.


(Azriel Hoh) #2

That would work, though I believe it was intentionally designed that way – it relates to the issue where (currently) we cannot load prefabs from multiple files. Can’t find a github issue, but it’s been mentioned in chat a number of times, and in this topic: How to make Prefabs refer to each other?.

Currently it’s less duplication when writing prefabs, to reference the sprite sheet handle by index. If we store the handle in a hash map to allow referencing an already loaded sprite sheet by path, then I think we should have a middle enum type for the prefab:

pub enum SpriteSheetReference {
    Path(Path), // or ID?

That said, @kabergstrom would have better knowledge for how to do this, from discord:

In the new asset system I am building for Amethyst ( each piece of data will be globally addressable and indexed, so cross-asset references will be structured and easily traversed(edited)

This makes it easy to build and traverse a dependency graph for nested prefabs

1 Like

(Sergey Veselkov) #3

I played a little with the code and came to this:

1 Like