Skip to content

Cannot load assets during runtime. #155

@glintfishGH

Description

@glintfishGH

When trying to add an asset to a scene during runtime with assets.addSound (or just assets.add), it fails to load the asset.

Code for a repro:

class MainScene extends Scene {
    override function preload() {
		// These work normally.
        var sounds = [Sounds.MUSIC__T5___TIAMAT, Sounds.MUSIC__T5___TIAMAT];
        for (sound in sounds) {
            assets.add(sound);
        }
    }

    override function update(delta:Float) {
        if (status != PRELOAD) {
            checkForNewSong();
        }
    }

    /**
     * Scans the `assets/music` directory for new files
     */
    function checkForNewSong() {
        for (song in sys.FileSystem.readDirectory("assets/music")) {
            // Removes file extension.
            var _song = song.split(".")[0];

            // Checking if this asset exists in the assets object. Feel like a function for this should exist.
            // If it doesn't exist (or is null), then we found a new sound to load.
            if (@:privateAccess assets.assetsByKindAndName.get("sound").get('music/$_song') == null) {
                log.info('Found song $song');
                addSound(song);
            }
        }
    }

    function addSound(sound:String) {
        var _sound = sound.split(".")[0]; // Removes file extension.
        var id = 'sound:music/$_sound';

        assets.addSound(id);
        assets.load(); // Line 42
    }
}

After calling addSound, I get the following in my error log

Failed to load audio at path: music/Kunst 		ceramic/SoundAsset:112
Failed to load asset music/Kunst (SoundAsset(music/Kunst music/Kunst)) 		MainScene:42

Heres a video showcasing the issue.

sound_issue_repro.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions