S&box Wiki

Mounting assets at runtime

Mounting assets at runtime

Sometimes you might need to download and mount certain resources from asset.party at runtime. Maybe you're making a GMod style game with spawnable props, maybe you're procedurally generating something.

Example method

The Sandbox gamemode has a great method that allows you to download and mount models from asset.party.

static async Task DownloadAsset( string packageName) { var package = await Package.Fetch( packageName, false ); if ( package == null || package.PackageType != Package.Type.Model || package.Revision == null ) { // spawn error particles return; } var model = package.GetMeta( "PrimaryAsset", "models/dev/error.vmdl" ); // downloads if not downloaded, mounts if not mounted await package.MountAsync(); Precache.Add( model ); }