Client Server Entity Sync

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 {
...
}

i think the pattern is its the same only for non runtime generated entities.
the best way i can think of referencing specific entities is by comparing their translation

how does livelink solve this problem? how can they tell which entity was changed in the editor

You can not rely Version/Index.
In Netcode, all Entities that are synced between client/server have the GhostComponent, which stores an Id you can use to identify the entities.
So you would have to send that Id in the Rpc and then check which entity has a GhostComponent with that Id and destroy that.