Search Unity

Resolved Question about RPCs, ghost spawning, and execution order

Discussion in 'NetCode for ECS' started by PhilSA, Feb 21, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Edit:

    Turns out my problem described below had a simple solution that doesn't rely on any ordering or spawn acknowledgement messages:
    1. Server spawns Player and Character ghosts
    2. Server sends RPC containing the ghostId and spawnTick of these Player/Character ghosts
    3. Client receives the RPC but keeps the RPC entity alive as long as it hasn't found a match for both the Player ghostId and the Character ghostId. (we find those with the GhostReceiveSystem.SpawnedGhostEntityMap hashmap)

    I want to do the following, but I'm wondering if it would even work (I haven't yet tested, because of this issue):
    • When a client joins a server, the server spawns a "Player" ghost (entity that contains commands buffer and info about the player) and a "Character" ghost that this player controls
    • immediately send an RPC to all clients that will let the Player entity know which Character entity is associated to them (we remember the controlled character entity in the Player component)
    My reason for doing this sort of separate Player/Character setup is that I find it much more convenient for cases where the character ghost can get destroyed and respawned, or when you can switch which character/vehicle you control during the game, etc.... I like to separate the concepts of the "controller" (human or AI) and the "controlled thing", because it helps me not to lose the common data about who controls these various things.

    But in order for this to work, I'd need some sort of guarantee that the RPC will be deserialized only after these Player + Character ghosts were spawned. Is it possible to have this sort of guarantee? (without manually writing my own ghost spawn acknowledgement system)
     
    Last edited: Feb 21, 2021
    bb8_1 likes this.