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:
var e = commandBuffer.Instantiate(nativeThreadIndex, bulletPrefab);
commandBuffer.SetComponent(nativeThreadIndex, e, new GhostOwnerComponent {NetworkId = ghostOwner.NetworkId});
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.
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
/// <summary>
/// Convert an interpolated ghost to a predicted ghost. The ghost must support both interpolated and predicted mode,
/// and it cannot be owner predicted. The new components added as a result of this operation will have the inital
/// values from the ghost prefab.
/// </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.
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.
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.
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.