SDT1310: RmlDataEvent On Static Method

Property Value
Rule ID SDT1310
Title RmlDataEvent On Static Method
Category UI
Severity Error

Cause

A static method is decorated with the [RmlDataEvent] attribute.

Rule Description

RmlUi data events are bound as instance delegates to a specific, instantiated RmlDataModel. Event handlers typically modify instance fields, update data structures, and invoke FlagDirty() to refresh the UI. Static methods cannot be bound as model instance callbacks.

How to Fix Violations

Remove the static modifier from the method so it becomes an instance method on the containing model.

Violation:

public sealed class HudModel(RmlDataModelToken token) : RmlDataModel(token)
{
    [RmlDataEvent]
    public static void OnExitClicked()
    {
        // ...
    }
}

Fix:

public sealed class HudModel(RmlDataModelToken token) : RmlDataModel(token)
{
    [RmlDataEvent]
    public void OnExitClicked()
    {
        // ...
    }
}

When to Suppress Warnings

Danger

Do not suppress this error. Static methods cannot be registered as instance event delegates in RmlUi, preventing the event handler from registering or executing.