Mod Loader/Reference/Accessory prefab API
An accessory's name, price, tags and icon are registered when its pack loads. Its model and materials are created when the game first needs them. This also applies to accessories added by importing a dress. Packs don't need an extra JSON setting.
Use AccessoryPrefabApi.GetPrefab(accessory) before copying or inspecting an accessory model in a C# plugin. Reading the game's accessory.prefab field directly doesn't load it: while the item is waiting, that field holds its base accessory.
Get a model
Wait for the accessory catalogue before finding an item from a pack. Put this in your plugin's Awake method, with using System.Linq; and using DressmakerMods; at the top of the file:
AccessoryPrefabApi.WhenCatalogReady(() =>
{
var accessory = AccessoryDefinition.AllAccessoryDefinitions
.FirstOrDefault(item => item.name == "my-pack.ribbon");
if (accessory == null) return;
AccessoryPrefabApi.Request(accessory,
prefab => Logger.LogInfo("Loaded " + prefab.name),
error => Logger.LogError("Could not load ribbon: " + error.Message));
});
Replace my-pack.ribbon with the pack ID, a dot, and the accessory ID. Request loads the prefab and calls one of the callbacks before returning. It doesn't start a background task. Call these methods on Unity's main thread.
The returned prefab belongs to Mod Loader and is shared. Don't destroy it or change its materials. Make a copy with UnityEngine.Object.Instantiate(prefab) if your plugin needs its own object. Trim prefabs are kept under an inactive parent so their input and placement scripts don't run during loading.
Methods
| Member | Use |
|---|---|
bool IsCatalogReady
|
Whether startup accessory registration has finished. This doesn't mean every model has loaded. |
void WhenCatalogReady(Action callback)
|
Run once after registration, or immediately if it has finished. |
AccessoryItem GetPrefab(AccessoryDefinition accessory)
|
Load the model if needed and return its shared prefab. Later calls return the same object. Throws if loading fails. |
AccessoryPrefabState GetState(AccessoryDefinition accessory)
|
Check Pending, Loading, Ready or Failed without loading anything. Native accessories are already ready.
|
Exception GetError(AccessoryDefinition accessory)
|
Read the recorded loading error, or null if none was recorded.
|
void Request(AccessoryDefinition accessory, Action<AccessoryItem> ready, Action<Exception> failed)
|
Load now and call ready, or call failed with the error. Both callbacks are required.
|
Listen for loaded models
Subscribe to PrefabReady if your plugin needs to react whenever a deferred model is created. It passes the accessory definition and its prefab. PrefabFailed passes the definition and the exception. These events only report new loading attempts; they don't replay items that loaded before you subscribed.
private void Awake()
{
AccessoryPrefabApi.PrefabReady += OnPrefabReady;
}
private void OnPrefabReady(AccessoryDefinition accessory, AccessoryItem prefab)
{
Logger.LogInfo("Accessory model ready: " + accessory.name);
}
private void OnDestroy()
{
AccessoryPrefabApi.PrefabReady -= OnPrefabReady;
}
A failed model keeps its registered ID and uses the base accessory in game. Check the error, fix the pack and restart to try again. Failure callbacks run once for that attempt. An exception in a callback is logged and doesn't prevent other subscribers from running.
To supply a prefab factory from your own plugin, use AccessoryModApi.RegisterFactory.
Textures and first use
Creating the prefab may load a small texture preview first. For a screenshot or another operation that needs the full image immediately, use ModTextureApi.Pin on each managed texture and dispose the returned handle afterwards.
Opening the accessory shop can create several models at once: the game builds its filtered item list, including items beyond the visible shelf. Deferring that work makes startup lighter, but the first shop visit can still take time with large packs.