menu_bookDocumentation

Custom Assets: GameResource Definition with Inspector and Hotloading

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

Define custom asset types as GameResource in s&box. They provide inspector windows, are hotloaded in-game, and are stored as JSON files with custom extensions.

Creating a Custom Asset Type

CSHARP
[AssetType( Name = "Clothing Definition", Extension = "clothing", Category = "citizen" )]
public partial class Clothing : GameResource
{
    public string Title { get; set; }

    [ResourceType( "vmdl" )]
    public string Model { get; set; }

    [Hide]
    public int Amount { get; set; }

    protected override Bitmap CreateAssetTypeIcon( int width, int height )
    {
        return CreateSimpleAssetTypeIcon( "checkroom", width, height, "#fdea60", "black" );
    }
}
Important: File extension must be all lowercase and ≤8 characters.

Accessing Assets

CSHARP
// Load by path (returns null if not found)
var clothing = ResourceLibrary.Get<Clothing>( "config/tshirt.clothing" );

// TryGet pattern
if ( ResourceLibrary.TryGet<Clothing>( "config/tshirt.clothing", out var loaded ) )
    Clothing = loaded;

Building a Static Registry

Use PostLoad to maintain a list of all loaded assets:

CSHARP
public partial class Clothing : GameResource
{
    public static IReadOnlyList<Clothing> All => _all;
    internal static List<Clothing> _all = new();

    protected override void PostLoad()
    {
        base.PostLoad();
        if ( !_all.Contains( this ) )
            _all.Add( this );
    }
}

Custom assets automatically appear in the Asset Browser "New" menu under their specified category. All standard property attributes work on GameResource properties.

Was this helpful?