Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Client data persistence during ghost irrelevancy

Discussion in 'NetCode for ECS' started by duova, Jan 14, 2023.

  1. duova

    duova

    Joined:
    Mar 15, 2021
    Posts:
    3
    Hi,

    From my understanding, if a ghost is irrelevant it will be destroyed by the client, and it will be instantiated when relevant again. What if I wanted to preserve some data on the client's ghost entity? Right now I'm trying to use game object animations, which means the entity needs a reference to the game object (or vice versa but the same issue applies). Is there a better way than to just relocate the game object/entity every time a ghost becomes relevant from irrelevancy? This is quite important for this use case because I plan on changing ghost relevancy quite often.

    Even if the data is kept somewhere else it would have to be indexed by entity, and that doesn't work if the entity id changes after irrelevancy.

    Cheers
     
  2. duova

    duova

    Joined:
    Mar 15, 2021
    Posts:
    3
    Quick Update:
    I've stumbled upon Unity.NetCode.Hybrid. (Wondering why there's so little mention of it. It seems useful, and it is definitely not on the docs.) So I'm wondering whether the GhostPresentationGameObjectEntityOwner can keep track of the entity after it has become relevant again after irrelevancy.
     
  3. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    326
    Hey rezonabyt!

    @timjohansson may have some best practices in mind for this (and `GhostPresentationGameObjectEntityOwner`), but your idea to persist game-state using the entity is almost viable (see below).

    Instead, you can index persistent data via a persistent ID made up of the `GhostComponent.ghostId` + `GhostComponent.spawnTick`, which should persist through relevancy destruction.

    Cheers!
     
    duova likes this.
  4. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    By "not in the docs" for Unity.NetCode.Hybrid you mean the manual? It has at least some coverage in the scripting api docs, see for example https://docs.unity3d.com/Packages/c...d.GhostPresentationGameObjectEntityOwner.html .

    GhostPresentationGameObjects will be destroyed and re-created with the entity that owns it - also if it is destroyed due to becoming irrelevant, so you cannot use it to store state for irrelevant ghosts. We are considering adding pooling for the GameObjects in the future but we are not working on it yet so it will not be part of 1.0.

    There is currently no way to prevent the despawn when a ghost becomes irrelevant so the method @NikiWalker mentioned is your best bet.