Skip to content

Asset Management

shmellyorc edited this page Sep 13, 2026 · 4 revisions

Asset Management

VOID's asset system loads, caches, unloads, and reloads game content through a mount-based virtual file system.

Game code asks for a virtual path. AssetManager searches the active mounts in order, creates the requested asset type, caches it, and handles its reloadable lifecycle.

Loading Assets

var texture =
    AssetManager.Instance.Load<Texture>(
        "Graphics/player.png");

var sound =
    AssetManager.Instance.Load<Sound>(
        "Audio/explosion.wav");

var map =
    AssetManager.Instance.Load<LDtkMap>(
        "Maps/level1.ldtk");

var shader =
    AssetManager.Instance.Load<Shader>(
        "Shaders/glow.shader");

Paths are relative to GameSettings.Instance.AppContentRoot.

The first active mount containing the path wins.

Asset Caching

Loading the same normalized path again returns the cached asset instead of recreating it.

var a =
    AssetManager.Instance.Load<Texture>(
        "Graphics/player.png");

var b =
    AssetManager.Instance.Load<Texture>(
        "Graphics/player.png");

// Same cached asset.

Cached assets can still be unloaded by the eviction system. Their source data is retained so they can become valid again when loaded later.

Automatic Eviction

Managed assets track LastAccessTime.

When an asset load reaches an eviction check interval, VOID can unload one valid cached asset that has been idle longer than the configured timeout.

Defaults are currently:

  • 30 minutes idle before eviction
  • periodic checks controlled by AssetCheckIntervalMinutes

Configure them at startup:

GameSettings.Instance
    .SetAssetEviction(30)
    .SetAssetCheckIntervalMinutes(5);

SetAssetEviction accepts 15 through 240 minutes. The check interval accepts 1 through 60 minutes.

Eviction calls Unload(), not final disposal. A managed asset should therefore retain enough source data to support a later Load().

Supported Asset Types

Built-in loaders include:

  • Texture
  • Sound
  • Shader
  • LDtkMap
  • SpriteFont
  • Spritesheet

For system-specific details, see:

Loading Fonts with Settings

Load a SpriteFont with its settings once:

var font =
    AssetManager.Instance.LoadSpriteFont(
        "Fonts/arial.png",
        spacing: 0f,
        lineSpacing: 1.2f,
        charset: SpriteFont.CharsetFull);

Later loads of the same path return the cached font:

var sameFont =
    AssetManager.Instance.Load<SpriteFont>(
        "Fonts/arial.png");

Custom Asset Types

A custom asset implements IAsset.

The important lifecycle rule is:

  • Load() makes the asset usable and refreshes LastAccessTime
  • Unload() releases reloadable resources but keeps enough source data to load again
  • Dispose() performs final cleanup

Example:

public sealed class DialogueAsset : IAsset
{
    public uint Id { get; }
    public string Tag { get; }
    public byte[] Data { get; }

    public bool IsValid { get; private set; }

    public AssetType Type =>
        AssetType.Normal;

    public DateTime LastAccessTime
    {
        get;
        private set;
    }

    public DialogueAsset(
        uint id,
        byte[] data,
        string tag)
    {
        Id = id;
        Data = data;
        Tag = tag;
    }

    public void Load()
    {
        // Parse/create reloadable state from Data.
        LastAccessTime = DateTime.Now;
        IsValid = true;
    }

    public void Unload()
    {
        // Release reloadable resources.
        IsValid = false;
    }

    public void Dispose()
    {
        Unload();
    }
}

Register it:

AssetManager.Instance
    .RegisterAssetType<DialogueAsset>(
        new[] { ".dialogue" },
        (id, data, tag) =>
            new DialogueAsset(
                id,
                data,
                tag));

Then load it normally:

var dialogue =
    AssetManager.Instance
        .Load<DialogueAsset>(
            "Dialogue/intro.dialogue");

See Extensibility for more extension examples.

Mount System

AssetManager searches mounts from first to last.

The normal loose-file content mount is present by default. On macOS, VOID also installs its platform content mount as needed.

Add a custom mount at highest priority:

AssetManager.Instance
    .AddMountToStart(
        new MyMount());

Lowest priority:

AssetManager.Instance
    .AddMountToEnd(
        new MyMount());

Or insert at a specific position:

AssetManager.Instance
    .InsertMount(
        1,
        new MyMount());

Loading a Pack

LoadPack creates a pack mount. It does not automatically add that mount to the asset search order.

var pack =
    AssetManager.Instance.LoadPack(
        "GameAssets.pack");

AssetManager.Instance
    .AddMountToStart(pack);

If GameAssets.key is beside GameAssets.pack, VOID discovers it automatically.

You can provide a key path explicitly:

var pack =
    AssetManager.Instance.LoadPack(
        "GameAssets.pack",
        "Keys/GameAssets.key");

AssetManager.Instance
    .AddMountToStart(pack);

Once mounted, game code uses the same virtual asset paths whether data comes from loose files or a pack.

Loading Multiple Packs

LoadAllPacks opens each top-level .pack file in a content directory and returns the mounts that opened successfully.

It does not add them to the search order automatically:

var packs =
    AssetManager.Instance
        .LoadAllPacks("Packs");

foreach (var pack in packs)
{
    AssetManager.Instance
        .AddMountToEnd(pack);
}

Choose AddMountToStart, AddMountToEnd, or InsertMount based on the priority you want.

Clearing Mounts

Restore VOID's default mount configuration:

AssetManager.Instance.ClearMounts();

Asset Packer Integration

VOID's pack system provides authenticated encryption, compression, integrity checking, streaming reads, and incremental updates.

See:


Back to Home

Clone this wiki locally