This is a rather complex problem I've been stuck on for a while.
I'm building a solution where I deserialize content (e.g., level configs, entities) from JSON payloads using the new com.unity.serialization.json package. Each JSON object includes a "Definition" node (a string key) that needs to be indexed into a runtime catalog for lookups. To ensure reliable resolution (e.g., turning a key like "ProjectilePrefab" into a GameObject), the lookup must happen after all the objects are deserialized and registered in the catalog, as doing it mid-deserial (via adapters) risks "half-done" results, where someone might attempt to reference something that has not been created yet, especially for staggered dependencies where the catalog sources are in the same JSON.
The challenge escalates with cross-object references: For example, in a struct like this:
public struct EntityConfig : IComponentData
{
public Entity EntityPrefab; // To be populated via catalog lookup on Definition
public EntityConfig NestedEntityConfig; // To be populated via cross-ref to another EntityConfig's instance
}
Dictionary<string, EntityConfig> KeysToEntityConfigs = ...
[
{
"Definition": "FirstDef",
"Type": "EntityConfig",
"Data": {
"EntityPrefab": "SomeEntity"
"NestedEntityConfig": "SecondDef"
},
},
{
"Definition": "SecondDef",
"Type": "EntityConfig",
"Data": {
"EntityPrefab": "..."
"NestedEntityConfig": "..."
},
}
]