API lifetime rules
Context content APIs
Prefer context.Items.Add(item), context.Buffs.Add(buff) and context.Skills.Add(skill) in Load(ModContext context). The owning context is supplied automatically. Use context.Items.Give(item) and context.Buffs.Apply(buff, target, turns) for operations. Inside item, consumable, buff and skill subclasses, use the inherited Context property, for example Context.Buffs.Apply(buff, target, 3).
This allows your mod to use namespaces such as MyMod.Items, MyMod.Buffs and MyMod.Skills without qualifying the StoneForge static classes. The old static APIs continue working. Registration, duplicate checks and unload cleanup share their existing implementations; content keys remain game-wide and must still be unique. Item queries and buff operations are not restricted to content owned by the context.
Instances, handles and assets
- Store room instances as
Instanceor callPersist()for an explicitly ID-only reference. CheckExistsbefore use; IDs are identities in the running game, not save-file identities. - An
Instancehanded to a callback is good for that callback; keep one longer withPersist(). A struct read throughInstance(not as aGmStruct) is the same. Arrays and structs held asGmArray/GmStructare kept alive for the game's garbage collector until they're disposed or C# stops referring to them (see Values). - Native function failures raise
GameCallException. Missing variable reads still returnUndefined. Native engine crashes or GML failures that bypass the bridge's status return are not converted into recoverable managed exceptions. - Load sprites and sounds through
ModContextfor ownership tracking. Do not manually delete an owned sprite/stream: the loader needs its ID for retirement and cleanup. - A paused mod keeps imported sprites alive until unload. Its registered callbacks stop, and its windows close on the next frame. Resetting failure state/reloading is explicit.