SDT1305: Uninitialized RML Data Member

Property Value
Rule ID SDT1305
Title Uninitialized RML Data Member
Category UI
Severity Error

Cause

A complex RML data member (IRmlDataStruct, IRmlDataScalar, or IRmlDataArray) decorated with [RmlDataVariable] is not initialized to a non-null instance upon construction.

Rule Description

When an RmlDataModel or IRmlDataStruct is bound, RmlUi recursively traverses nested structs and collections to register child data definitions. If a member implementing an RML data interface is null when binding occurs, RmlUi cannot reflect its members or construct the binding hierarchy, leading to runtime null reference exceptions.

How to Fix Violations

Initialize the member to a non-null instance using a field initializer or inside the constructor.

Violation:

public sealed class GameDataModel(RmlDataModelToken token) : RmlDataModel(token)
{
    // Uninitialized complex member!
    [RmlDataVariable] public ItemEntry ActiveItem;
    [RmlDataVariable] public SimpleVariantArray Tags;
}

Fix:

public sealed class GameDataModel(RmlDataModelToken token) : RmlDataModel(token)
{
    [RmlDataVariable] public readonly ItemEntry ActiveItem = new();
    [RmlDataVariable] public readonly SimpleVariantArray Tags = [];
}

When to Suppress Warnings

Danger

Do not suppress this error. Complex RML members must not be null when data models are created. RmlUi inspects instances at registration time and will fail if any nested member is null.