Changes

→‎Content: + reload assets
Line 524: Line 524:  
     }
 
     }
 
}
 
}
 +
</source>
 +
}}
 +
 +
====Reload assets====
 +
{{SMAPI upcoming
 +
|version = 2.0
 +
|content = '''Caution:''' reloading assets is fairly expensive, so use this API judiciously to avoid impacting game performance.
 +
 +
You can reload an asset by invalidating it from the cache. It will be reloaded next time the game requests it (and mods will have another chance to intercept it), and SMAPI will reload it automatically if it's a core asset that's kept in memory by the game. For example, this lets you change what clothes an NPC is wearing (by invalidating their cached sprites or portraits).
 +
 +
Typically you'll invalidate a specific asset key:
 +
<source lang="c#">
 +
helper.Content.InvalidateCache("Data\ObjectInformation.xnb", ContentSource.GameContent); // path separators and capitalisation don't matter
 +
</source>
 +
 +
In ''extremely rare'' cases, you may need to invalidate all assets of a given type. This is very expensive and may have a noticeable impact on game performance. Don't do this unless you're absolutely sure you need to.
 +
<source lang="c#">
 +
helper.Content.InvalidateCache<Texture2D>();
 
</source>
 
</source>
 
}}
 
}}
translators
8,404

edits