"[GameResource] is obsolete: declare custom resources with [AssetType]"
▸ SYMPTOM
- A
GameResourcesubclass compiles, but the build reportsCS0618: 'GameResourceAttribute' is obsolete: 'Use AssetType instead'. CS0618is a warning, so a plaindotnet buildstill exits green and the message is easy to miss.- The warning only becomes a hard failure if the project treats warnings as errors, or a review gate demands zero warnings.
▸ CAUSE
The old attribute used a positional constructor:
[GameResource( "Spell", "spell", "A castable spell" )]
public class SpellDefinition : GameResource { }GameResourceAttribute is now marked obsolete in favor of AssetTypeAttribute. The compiler keeps honoring it for one more cycle, so nothing breaks yet, but the warning stands until you migrate.
▸ FIX
Swap the attribute for [AssetType] and pass named properties instead of positional arguments:
[AssetType( Name = "Spell", Extension = "spell", Category = "My Category" )]
public class SpellDefinition : GameResource { }The properties on Sandbox.AssetTypeAttribute (from Sandbox.Engine.xml) are Name, Extension, Category, TargetType, Flags, and IconColor.
There is no Icon property. The old [GameResource( ..., Icon = "auto_awesome" )] named argument does not carry over, so drop it during the swap. A headless dotnet build reports zero warnings and zero errors once the attribute is replaced.
▸ WHY IT WORKS
Only the declaring attribute changes. The type still derives from GameResource, still produces its .ext file, and is still returned by ResourceLibrary.GetAll<T>(). [AssetType] is the current name for the same registration, so moving to it clears CS0618 without touching how the resource loads or how you query it.
- Published