Is it possible to have an option where the ghost is only predicted when it is locally spawned?
Use case:
We need to make some ghosts, like projectiles, to be locally predicted when spawned and then switched to interpolated when they are classified. In this case, the OwnerPredicted option can solve the issue.
However, let’s imagine an ability where a projectile on collision creates another projectile that targets a nearby enemy.
A) If the first projectile collides before being switched to interpolated, it will be despawned (disabled on the client), and then the second projectile will be locally spawned and switched to interpolated in mid-air.
B) If the first projectile is switched to interpolated before collision, the second projectile will be spawned by the server directly as interpolated.
In the current version of the Netcode package, none of the default ghost modes can accomplish this behavior:
- Predicted: Any ghost projectile, even those owned by other clients, will be spawned as predicted. (bad for performance and bandwidth)
- Interpolated: This will not allow client-side prediction.
- OwnerPredicted: It is possible to achieve the desired behavior (B), but in a dirty manner, as the second projectile will be spawned as predicted even though it is spawned by a snapshot from the server. In this case, we would need to switch it back to interpolated, which is completely useless if it were directly spawned as interpolated.
If you set the mode to support both and default interpolated. You can notice that if you spawn on client you will actually do “predicted spawns”. You can then create a custom classification system that sets SpawnType to predicted. Then you just have to handle your custom logic of transferring projectiles between interpoalted or predicted however you wish, and if predicting projectile you can predict spawn the sub projectiles.
1 Like
Hey @Jawsarn ,
This is really good information! I’ll try it out tomorrow 
However, it would be easier if Unity supported this out of the box.
Thanks!
With a custom classification system is up to you to define what spawning behavior you want. So by setting the mode to all and then setting the default spawning to interpolated (for example) you can still select to spawn the received ghost from the server as predicted if you like (this is up to the classification system to do, it is not bound to work only for predicted spawned ghosts).
So technically, you can configure the projectile as predicted and based on the owner set the interpolation mode for non owning clients if you like already (so no prediction cost). For the second projectile (if you have a way to detect that is a second projectile, if you are using predicted spawning you can do), you can match the spawned entity (so no new entity is spawned) for this ghost, and queue up a transition from predicted to interpolated there.
At least i would try it out and see if with little changes (if something does not work) it can solve the case number B
1 Like