#Deleting a ghost entity. Use an RPC or a ghost component?

1 messages · Page 1 of 1 (latest)

tame crown
#

I want a client to be able to delete a ghost they own. Is it better to:

  • Set a field like "PleaseDeleteMe" on a syhnchronized ghost component and make a system on the server to read that field and delete the entity?
  • Use a separate RPC? If I use an RPC how do I refer to the entity I want to delete? If I just have an Entity reference in the RPC will that reference be valid on the server side too? If not is there a better alternative?
vestal ether
#

I prefer rpc in this case. It will be some action anyway, and it server will despawn ghost.
Also there are something wrong with client deleting some ghosts - client should be ready to spawning/despawning ghosts rapidly (via relevancy for example) and never decide anything about them

#

Rpc with entity field will be retargeted properly if it points to some ghost

tame crown
tame crown
# vestal ether Rpc with entity field will be retargeted properly if it points to some ghost

RPC with Entity target worked perfectly, thanks!

Is there any more efficient way to check if the request is coming from the correct client than this?

        foreach (var (reqSrc, requestComponent, reqEntity) in SystemAPI
                     .Query<RefRO<ReceiveRpcCommandRequest>, RefRO<DespawnCrewMemberRequest>>()
                     .WithAll<DespawnCrewMemberRequest>().WithEntityAccess()) {
            commandBuffer.DestroyEntity(reqEntity);
            
            // Make sure the network ID on the request matches the network ID of the entity they want to delete
            NetworkId networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection];
            Entity targetEntity = requestComponent.ValueRO.TargetEntity;

            GhostOwner owner = state.EntityManager.GetComponentData<GhostOwner>(targetEntity);
            if (owner.NetworkId != networkId.Value) continue; // The IDs don't match

            // otherwise, delete the entity!
            commandBuffer.DestroyEntity(targetEntity);
        }```
torpid shore
#

you should probably check the entity is allowed to be destroyed

#

otherwise the client could delete any ghost they own

#

rather than just one of their crew members

tame crown
#

Good point!

For now the only ghosts they own are the crew members but that might change later.

quasi mirage
#

Your option A should be to put it in the Command, since that's how Client can send state to server. But the better option is B if it is not meant to be something that is predicted.