🤑 Indie game store🙌 Free games😂 Fun games😨 Horror games
👷 Game development🎨 Assets📚 Comics
🎉 Sales🎁 Bundles

Check if an asset exists?

A topic by Liam Brocklehurst created 1 year ago Views: 113 Replies: 2
Viewing posts 1 to 3

I might be missing something here, but I'm just wanting to check if an asset exists (from a path) before I assign it to something.

For example, I would do something like:

    this.mySprite.setSprite("Path/To/Sprite");

but I'd like to be able to do:

    if(AssetExists("Path/To/Sprite")
        this.mySprite.setSprite("Path/To/Sprite");

You could use a simple try / catch statement like so:

try {
this.mySprite.setSprite( "Path/To/Sprite" );
} catch( error ) {
Sup.log( error ); //Something went wrong, most likely the path to the asset doesn't exist
}
(+1)

Yeah I'm thinking that's what I might have to do, thanks!