This question was created in reference to: [Mass entities initializing fragments on the incorrect archetypes due to shared [Content removed]
With reference to the previous question, we have applied the suggested fix (CL 45139186); however, we are still experiencing some issues related to the behavior described there.
In UMassAgentSubsystem::HandlePendingInitialization, there is a FEntityCreationContext for all iterations of the PendingAgentEntities processing loop. This results in the CreationContext accumulating all EntityCollections created up to that point in the flow.
To illustrate what we are seeing, we have the following configuration:
* ActorA, with a MassAgentComponentA and EntityConfigA (containing Fragment1 and Fragment2).
* ActorB, with a MassAgentComponentB and EntityConfigB (containing Fragment1 and Fragment3).
In UMassAgentSubsystem::HandlePendingInitialization, there are two entries in PendingAgentEntities. We do not observe the issue during the first iteration of the loop.
However, during the second pass, within the flow UMassSpawnerSubsystem::SpawnEntities -> UMassSpawnerSubsystem::DoSpawning -> FMassEntityManager::BatchSetEntityFragmentValues, the call to CreationContext->GetEntityCollections(*EntityManager.Get()) returns two EntityCollection objects. These are then processed using the FragmentInstances belonging to EntityConfigB.
At this point, the Entity from ArchetypeA is being processed using the Fragments from ArchetypeB. This causes FMassArchetypeData::SetFragmentData to exhibit unexpected behavior regarding the memory of EntityA’s Fragments:
- Fragment1 (the one present in both configurations): It is reset to its initial values, overwriting any values assigned during the first iteration of the loop.
- Fragment3: It triggers a Warning (and previously triggered a FindCheck without CL 45139186) because Fragment3 does not exist in the archetype defined for EntityConfigA.
Our current understanding is that FMassEntityManager::BatchSetEntityFragmentValues should only operate on entities matching the EntityTemplate passed as an argument, but it seems to be affecting all collections within the CreationContext.
Is this understanding correct? Do you have any suggestions for a potential fix or a workaround we could apply here?
Thank you for your help.
[Attachment Removed]