Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

NETCODE: How to convert ghost entity index / version from client to server

Discussion in 'NetCode for ECS' started by fluke32, Jun 23, 2020.

  1. fluke32

    fluke32

    Joined:
    Jun 9, 2020
    Posts:
    12
    In the project I'm working on, I have a "agent" (player) entity ghost, and a set of "ability" entity ghosts, each of which has a "OwningPlayer" component that points to the owning player. When a player uses an ability, I want to send a message to the server that a specific ability needs to be used. My initial attempt at doing this was to add an "Entity" field to my ICommandData, and serialize the ability entity by its index and version. However, when I reconstruct the entity from the index and version in the server world, this doesn't work, because the index and version are different. Is there any way to convert an "Entity" reference of a ghost in the client world to the corresponding entity ghost in the server world? Or perhaps I'm going about this wrong and there is some other method I'm supposed to use?
     
  2. fluke32

    fluke32

    Joined:
    Jun 9, 2020
    Posts:
    12
    Ok it seems like the solution may be to change the CommandTargetComponent on the client side to the ability entity before sending the relevant commands, so the ability entity gets the commands directly (and then I don't have to worry about referencing the ability entity in the command). I will try this tomorrow.
     
  3. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    I use indices, so I refer by index in dynamic buffer of root ghost
     
  4. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    55
    Orimay likes this.
  5. fluke32

    fluke32

    Joined:
    Jun 9, 2020
    Posts:
    12
    Thanks for the replies!


    This is helpful however I'm still having some trouble. Where is the buffer of ghosts? My guess would be the "GhostCollection" entities, but I'm looking in the entity analysis window, and they only have a "GhostPrefabBuffer" that stores links to the prefab entities. I don't see anything with links to the actual instantiated entities.

    So, you have any ghosts that need to refer to eachother both be children of some parent ghost?
     
  6. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    Well, they aren't really children. They are referred via DynamicBuffer
     
  7. Orimay

    Orimay

    Joined:
    Nov 16, 2012
    Posts:
    304
    You might register ghostId in a collection on the ghost's spawn
     
  8. fluke32

    fluke32

    Joined:
    Jun 9, 2020
    Posts:
    12
    Thanks, that's what I ended up doing!