Instantiating a prefab containing a predicted ghost, with a child that is a ghost, causes error spam

Entities 1.2.3, Netcode for Entities 1.2.3

On the server I’m spawning a prefab containing a parent and a child. The parent has a ghost authoring component, set to predicted (if set to interpolated, there is no error). The child also has a ghost authoring component (settings do not matter).

Here’s the error

ArgumentException: An EntityManager command is operating on an invalid entity. This usually means that the Entity has already been destroyed or was never created. This can happen when a subscene is opened or closed between when a EntityCommandBuffer has been recorded and played back. This can invalidate recorded Entities. Entity(457:1) was previously destroyed by system Unity.Entities.BeginSimulationEntityCommandBufferSystem in world AClientWorld. This command was requested from system Unity.NetCode.PredictedGhostSpawnSystem.
Unity.Entities.EntityComponentStore.AssertEntitiesExist (Unity.Entities.Entity* entities, System.Int32 count) (at ./Library/PackageCache/com.unity.entities@1.2.3/Unity.Entities/EntityComponentStoreDebug.cs:315)
Unity.Entities.EntityStorageInfoLookup.get_Item (Unity.Entities.Entity entity) (at ./Library/PackageCache/com.unity.entities@1.2.3/Unity.Entities/Iterators/EntityStorageInfoLookup.cs:126)
Unity.NetCode.GhostPredictionDisableSimulateSystem+TogglePredictedJob.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 unfilteredChunkIndex, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) (at ./Library/PackageCache/com.unity.netcode@1.2.3/Runtime/Snapshot/GhostPredictionSystemGroup.cs:69)
Unity.NetCode.GhostPredictionDisableSimulateSystem+TogglePredictedJob.Unity.Entities.IJobChunk.Execute (Unity.Entities.ArchetypeChunk& chunk, System.Int32 unfilteredChunkIndex, System.Boolean useEnabledMask, Unity.Burst.Intrinsics.v128& chunkEnabledMask) <0x2470848e1d0 + 0x00072> in <128051a7d453428ea710933a9a4e80dd>:0
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].ExecuteInternal (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.unity.entities@1.2.3/Unity.Entities/IJobChunk.cs:420)
Unity.Entities.JobChunkExtensions+JobChunkProducer`1[T].Execute (Unity.Entities.JobChunkExtensions+JobChunkWrapper`1[T]& jobWrapper, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.unity.entities@1.2.3/Unity.Entities/IJobChunk.cs:363)

Instantiation code

Entity creature = state.EntityManager.Instantiate(_creaturePrefabComponent.Value);
public struct CreaturePrefabComponent : IComponentData
{
    public Entity Value;
}

Attaching screenshots of the prefab contruction

9890877--1427637--Prefab1.png


1 Like

Additional information, the error only occurs when I play in the editor and my subscene is open (live converted).

https://docs.unity3d.com/Packages/com.unity.netcode@1.0/api/Unity.NetCode.GhostAuthoringComponent.html

Ok, so according to this, only the root GameObject in a prefab may have a GhostAuthoringComponent.

However, in the game I am developing, I want to have a both the parent and child entities to have distinct physics shapes. When I remove the ghost component from the child, I get the following warning:

[AClientWorld] The default physics world contains 1 dynamic physics objects which are not ghosts. This is not supported! In order to have client-only physics, you must setup a custom physics world:

  • Entity(358:3)

If the answer is, a child of a ghost may not be a ghost, then my question becomes how should I conceptually author an entity with multiple physics shapes that is a ghost?

  • Is it ok to have parent/child relationships where both the parent and the child are ghosts?
  • Should I be just not using parent/child in this case, and instead synchronize transforms manually?

This forum post seems relevant

This doesn’t specifically address dynamic physics objects, however.

Fundamentally, my question is, what is the correct architectural approach to create entity pairs where both entities have a physics object, and transforms are synchronized, in a networked multiplayer game where both entities are predicted on the client.

When physics rigidbodies are baked, even for non-ghost entities, they’ll end up on different entities with no parent/child relationship. You can observe this at editor time if you open the Entities Hiearchy and set its mode to “runtime”, you’ll see that as soon as you add a rigidbody to a child, the baked entity is deparented.
In general, physics (both GameObject and entities side) do their calculation independent of hierarchy.
I’d possibly look at joints or look at tracking that association yourself.
We might want to highlight this better in Netcode’s baking thinking of it.

Thanks for the guidance Samuel!