codeAPI Reference

Sandbox.GameResource

calendar_today May 3, 2026 schedule ~1 min read person patrickjr verified 50

Sandbox.GameResource

Base class for custom asset types.

Overview

GameResource is the base class for creating custom asset types that appear in the editor with full hotloading support.

Creating a Custom Asset

CSHARP
[AssetType(Name = "Weapon Definition", Extension = "weapon", Category = "gameplay")]
public class WeaponDefinition : GameResource
{
    public string DisplayName { get; set; }
    public float Damage { get; set; }
    public float FireRate { get; set; }
    
    [ResourceType("vmdl")]
    public string Model { get; set; }
    
    [ResourceType("sound")]
    public string FireSound { get; set; }
}

AssetType Attribute

PropertyDescription
NameDisplay name in editor
ExtensionFile extension (max 8 chars, lowercase)
CategoryMenu category

PostLoad

CSHARP
public class WeaponDefinition : GameResource
{
    [JsonIgnore]
    public Model CachedModel { get; private set; }
    
    protected override void PostLoad()
    {
        base.PostLoad();
        
        if (!string.IsNullOrEmpty(Model))
        {
            CachedModel = Model.Load(Model);
        }
    }
}

Loading

CSHARP
// By path
var weapon = ResourceLibrary.Get<WeaponDefinition>("weapons/assault_rifle.weapon");

// Safe loading
if (ResourceLibrary.TryGet<WeaponDefinition>(path, out var weapon))
{
    // Use weapon
}

// Get all of type
var allWeapons = ResourceLibrary.GetAll<WeaponDefinition>();

Properties

CSHARP
// GameResource provides:
string path = resource.ResourcePath;
string name = resource.ResourceName;

Editor Features

  • Appears in asset browser
  • Draggable into component properties
  • Hotloads on save
  • JSON serialization

Inheritance

GameResources can inherit:

CSHARP
public class BaseItem : GameResource
{
    public string Name { get; set; }
    public int Cost { get; set; }
}

[AssetType(Name = "Weapon", Extension = "wpn")]
public class WeaponItem : BaseItem
{
    public float Damage { get; set; }
}
Was this helpful?