SDT1311: RmlDataEvent Outside RmlDataModel
| Property | Value |
|---|---|
| Rule ID | SDT1311 |
| Title | RmlDataEvent Outside RmlDataModel |
| Category | UI |
| Severity | Error |
Cause
A method decorated with [RmlDataEvent] is declared in a class that does not derive from RmlDataModel.
Rule Description
In RmlUi, data events (such as data-event-click="OnAction") are registered exclusively at the root model level through RmlDataModel. While data variables can be distributed across nested IRmlDataStruct types, event callbacks can only be declared directly on classes inheriting from RmlDataModel.
Decorating methods in an IRmlDataStruct, helper class, or service with [RmlDataEvent] will not register the callback with the UI event dispatcher.
How to Fix Violations
Move the event handler method into the root RmlDataModel class that owns the binding context.
Violation:
public sealed class ItemEntry : IRmlDataStruct
{
[RmlDataVariable] public int Id;
// Cannot handle RML events inside an IRmlDataStruct!
[RmlDataEvent]
public void OnUse()
{
// ...
}
}
Fix:
public sealed class ItemEntry : IRmlDataStruct
{
[RmlDataVariable] public int Id;
}
public sealed class InventoryModel(RmlDataModelToken token) : RmlDataModel(token)
{
[RmlDataVariable] public readonly GenericStructArray<ItemEntry> Inventory = [];
[RmlDataEvent]
public void OnUseItem(int itemId)
{
// ...
}
}
When to Suppress Warnings
Danger
Do not suppress this error. Methods outside an RmlDataModel will never be registered with the document event table, leaving your UI event handlers unresponsive.