Prefabs
Reconstructing an object that no longer exists — only through your factory, only with a recorded key, with the identity adopted from the save.
Restoring never instantiates anything by itself#
Four conditions must all hold, and each one is something you opted into:
- Capture recorded a
prefabKey— only if a component on the object implementsIPersistencePrefabSource. - The missing-object policy is
ReconstructThroughFactory. The default,Report, does not build anything. - The game installed an
IPersistencePrefabFactoryviaNexusForgePersistence.PrefabFactory. - The factory — and nothing else in the package — calls
Instantiate.
public sealed class MyPrefabFactory : IPersistencePrefabFactory
{
public bool TryCreate(string prefabKey, out GameObject instance)
{
class="tok-com"> // Your catalogue, your pooling, your addressables. Return false when the key is unknown,
class="tok-com"> // and the restore will report exactly that instead of leaving a half-built object behind.
return m_Catalogue.TryCreate(prefabKey, out instance);
}
}After a successful reconstruction the instance adopts the identity from the save, so the next capture still matches the same object rather than creating a second identity for the same thing.
When it does not happen, you are told which part is missing#
The report distinguishes the three failures, because they have three different fixes:
| Missing | What it means | Fix |
|---|---|---|
| No key | Capture never recorded one | Implement IPersistencePrefabSource on a component of the object |
| No factory | The game installed none | Set NexusForgePersistence.PrefabFactory during initialisation |
| Unknown key | The factory refused it | Add the key to your catalogue, or keep Report for that case |
MissingPrefabPolicy chooses whether an unsatisfiable key is a report, a warning or a failure.
Next#
- References — the general resolution path.
- Restore — policies and presets.
- Extending NexusForge — the factory seam in context.
Something wrong on this page? Every page here describes behaviour that is checked in the repository. If a page and the package disagree, the package wins.
Report a documentation problem · Frequently asked questions · Troubleshooting