[Netcode] How does a GhostCollection match ghost types?

How does a GhostCollection match ghost types? The GhostCollection docs don’t seem to say. I’m having trouble reverse engineering (or finding) the criteria used for a GhostCollection when matching ghost types. Here’s what I think are the most insightful case, with a vanilla unity project:

I created 3 cube prefabs, each with increasing x scale so I could tell them visually apart. Cube1 has physics components, Cube 2 has a TestComponent with a synchronized [GhostDefaultField], and Cube3 has both. I instantiate all three cubes in succession, in a system:

                var ghostCollection = GetSingleton<GhostPrefabCollectionComponent>();
                var cube1GhostId = TinyGhostSerializerCollection.FindGhostType<Cube1SnapshotData>();
                var cube1Prefab = EntityManager.GetBuffer<GhostPrefabBuffer>(ghostCollection.serverPrefabs)[cube1GhostId].Value;
                EntityManager.Instantiate(component.prefabCube1);

However, despite these three entities having different archetypes, a GhostCollection with the prefabs in order – Cube1, Cube2, Cube3 – doesn’t work. All three instantiated cubes are the same (Cube1). However, if I reverse the order – Cube3, Cube2, Cube1 – this works. All three instantiated cubes are different. This begs a few more specific questions:

  • Are archetypes used for matching?
  • Are components without any GhostDefaultFields checked when matching?
  • Are components with GhostDefaultFields checked when matching?

Archetypes are used for matching :c
Serializers are looked up per chunk, so they could use SharedComponentData for this purpose (to find the matching prefab), but they don’t. I managed to handle this manually. Here’s how:
DOTS NetCode: MMO locations, portals, items

Yes, the serailizer will go over the list of ghost types in the order they are defined in the collection. For each type if checks if the current entity has all the components the ghost type needs. It does this matching per chunk, based on the archetype owning the chunk. If it does have all the components, if picks that type. This means the order in the collection matters.
We will probably change this to be more robust in the future.

It will check for all components which have the “server” checkbox checked, regardless of if they have any serialized data or not.