Are you able to fetch entities by just constructing a new entity with the corresponding index and version? and more importantly, will an entity have the same version and index on the server and on every client?
looking at the entity debugger, it surprisingly seems to be so, but im not sure if it’ll always be the case or if its just a coincidence
would something like this work?
[UpdateInGroup(typeof(ServerSimulationSystemGroup))]
class DestroyEntitySystem : ComponentSystem {
protected override void OnUpdate() {
Entity toDestroy = GetSingleton<Tag_ToDestoy>();
Entities
.WithAll<NetworkIdComponent>()
.ForEach((Entity connectionEnt) => {
Entity rpcEntity = PostUpdateCommands.CreateEntity();
DestroyEntityRPC destroyEntityRpc = new DestroyEntityRPC{index = toDestroy.Index, version = toDestroy.Version};
PostUpdateCommands.SetComponent(rpcEntity, destroyEntityRpc);
PostUpdateCommands.AddComponent(rpcEntity, new SendRpcCommandRequestComponent { TargetConnection = connectionEnt });
});
}
}
[UpdateInGroup(typeof(ClientSimulationSystemGroup))]
class ProcessDestroyRPC : ComponentSystem {
protected override void OnUpdate() {
Entities
.ForEach((Entity reqEnt, ref DestroyEntityRPC rpc, ref ReceiveRpcCommandRequestComponent reqSrc) => {
Entity toDestroy = new Entity{Version = rpc.version, Index = rpc.index};
PostUpdateCommands.DestroyEntity(toDestroy);
PostUpdateCommands.DestroyEntity(reqEnt);
});
}
}
class DestroyEntityRPC : IRpcCommand {
...
}