Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Netcode - Transfering ghost ownership during runtime

Discussion in 'NetCode for ECS' started by mickee, Sep 1, 2021.

  1. mickee

    mickee

    Joined:
    Dec 26, 2013
    Posts:
    11
    Hi,

    I am synchronizing ghost with Owner Predicted default ghost mode.
    At some point I would like to transfer the ownership to some other player during runtime.

    Is it possible to do so ?

    In the Asteroids example and the documentation, there is no info about whether this is possible or not:
    Code (CSharp):
    1. var e = commandBuffer.Instantiate(nativeThreadIndex, bulletPrefab);
    2. commandBuffer.SetComponent(nativeThreadIndex, e, new GhostOwnerComponent {NetworkId = ghostOwner.NetworkId});
    Can we change the NetworkId after ?

    Thanks for your help,
     
  2. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    86
    Hello @mickee

    it is a very interesting question.

    Is it possible to change the owner of Network object during runtime ?
    Or have a Network object with multiple owner ?

    Thanks for your help ! @timjohansson @CMarastoni
     
  3. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Changing the owner is not possible when using owner predicted. Owner predicted means it picks predicted or interpolated mode at spawn time on the client, and the server uses the owner to know if the client is predicting or interpolating the ghost.

    If you change the owner on the client that will just get overwritten with the server state since it is ghosted.
    If you change the owner on the server it will send the new owner to the client, but the client will not switch between predicted / interpolated. The server will assume the client did though, so it will send the wrong data if the ghost has predicted only or interpolated only components.

    There is currently no way to switch between interpolated and predicted mode after spawning, we are investigating ways to make that possible but I do not know when that will be available.
    We have so far not considered using that for changing owner on owner predicted ghosts, but it sounds like it would be useful so I will add a task to our backlog to investigate if that would be possible.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,734
    Is there any news on this? I believe there is support from switching between interpolated and predicted via
    GhostPredictionSwitchingSystem but it specifically says not supported for owners

    Code (CSharp):
    1. /// <summary>
    2. /// Convert an interpolated ghost to a predicted ghost. The ghost must support both interpolated and predicted mode,
    3. /// and it cannot be owner predicted. The new components added as a result of this operation will have the inital
    4. /// values from the ghost prefab.
    5. /// </summary>
    (Random note, typo on `Inital`)

    This has been a blocking me for a while. Core aspect of my project is taking and releasing ownership of NPC units at will and I'm struggling to figure out how to implement this without either

    - having support for swapping ghost owners at runtime
    - or simply don't use ghost owners and do everything interpolated, but I feel like netcode is suddenly looking a lot less attractive to other solutions at this point =(

    Think dota 2 helm of dominator or enchantress/chen etc mechanics of mind control.
     
    Last edited: Jan 3, 2023
  5. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    286
    EDIT2: Forget what I said, I'll need to clarify before giving an update.
     
    Last edited: Jan 13, 2023
  6. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    873
    You can switch from interpolated to predicted any ghost that is setup to support both modes. And it should technically work also for owner-predicted ghosts. However, there may be some little caveats in some places in the current Netcode for Entities implementation that need to be investigated and that may prevent something to work as expected.

    There is nothing really nothing big preventing you making this behaviour work. But sure requires some custom system on your end to ensure the mode is setup correctly, given the current owner of the ghost, on the client and the server.

    But I would say, a sample showcasing this (very common case actually, i.e a vehicle), is definitely worth.
     
    Jawsarn likes this.
  7. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,734
    Thanks for the info CMarastoni. I'm mostly doing preproduction work so I'm glad to know it's likely possible and I can tick this box. A sample would definitely be appreciated.
     
    FWCorey likes this.
  8. ScallyGames

    ScallyGames

    Joined:
    Sep 10, 2012
    Posts:
    38
  9. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    286
    Hey all! Happy to confirm that this is fixed and working in 1.2.0-exp.3 (credit to Cristian). See CHANGELOG entry:
    * when the server change owner for a ghost configured as owner-predicted, the ghost automatically switch the operation mode from interpolated to predicted (or vice versa) based on the owner.
     
    Opeth001, cj-currie and tertle like this.