reckfellENGINE

C#: a custom Resource with GlobalClass

Register ShotSettings, save .rdata and distinguish registration from a singleton.

On this page

Declare the type

Save this class as ShotSettings.cs with identical casing. It derives from Resource to store settings rather than occupy the Entity tree. Add it to the existing C# project and build. After refreshing the script list, the editor can offer the registered type when creating resources. In code, use ordinary new ShotSettings().

ShotSettings.cs
C#
using Reckfell;

[GlobalClass]
public partial class ShotSettings : Resource
{
    [Export] public string DisplayName { get; set; } = "Pulse";
    [Export(PropertyHint.Range, "1,100,1")] public int Damage { get; set; } = 12;
    [Export] public Reckfell.Collections.Array<string> Tags { get; set; } = new() { "weapon" };

    public bool TryGetDamage(out int damage)
    {
        damage = 0;
        if (Damage < 1 || Damage > 100) return false;
        damage = Damage;
        return true;
    }
}

GlobalClass identifies an editor type. It creates no shared instance, makes no methods static and does not replace an autoload. Two weapons can reference one ShotSettings: changing its Damage affects both. Store per-weapon ammo on each instance, as _ammo in the export example.

Save and verify

ResourceSaver.Save(settings, "user://shot-settings.rdata") returns Error: check it before loading. ResourceLoader.Load<ShotSettings> returns a typed resource; handle null. To test reading from disk rather than the shared cache, specify CacheMode.Ignore. This produces a separate instance; ordinary loading may reuse a cached resource.

The complete fixture verifies save/load, name/damage/tags and the restored C# type. A headless editor import registers ShotSettings with Resource as its base in GetGlobalClassList. This does not test a user's actions in Create Resource.

If the type is missing

Check the build, exact ShotSettings.cs/ShotSettings spelling, GlobalClass and ReckfellObject inheritance. Decorating an ordinary C# class produces RF0401; a generic class produces RF0402. InventoryLedger is an ordinary model and needs no GlobalClass. After renaming a file, fix its class and references and rebuild; registration alone does not migrate existing resources.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.