Search Unity

Question about prediction: "Predicted" vs "Owner Predicted"

Discussion in 'NetCode for ECS' started by PhilSA, Feb 13, 2021.

  1. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    From the manual: https://docs.unity3d.com/Packages/com.unity.netcode@0.6/manual/ghost-snapshots.html


    The "Predicted" ghost mode implies everyone will predict the ghost, and I'm not sure what this means exactly. Does that mean that every client should be recieving the player commands of the remote owning player of that ghost, so they can run a bunch of prediction frames using the last know commands?

    And if so, how should a client be set up to receive the player commands of other clients?
     
    Last edited: Feb 14, 2021
    GameDeveloper1111 and bb8_1 like this.
  2. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    This is completely a guess on my part, but I would assume that all players should be owner predicted and that predicated is used for things that cannot tolerate being interpolated. I would use owner prediction for all players in the game and use prediction for something that a player may control some of the time (like a vehicle).
     
    bb8_1 likes this.
  3. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Predicted was originally mostly meant for things that are not directly controlled. If you have an object you can interact with you might or example want to have it predicted so the interactions are not delayed. Predicted just means apply the latest snapshot and run the simulation, it is not exclusive to the character you control and you can predict also if the simulation does not use any input other other form of player control (for example your own projectiles in asteroids are owner predicted). With recent versions of netcode it is also possible to predict other players.

    Switching an object to "Predicted" will not automatically send inputs - you can start sending inputs for other players by adding [GhostField] to all fields and a [GhostComponent(OwnerSendType=SendToOwnerType.SendToNonOwner)] to your ICommandData implementation if you want to run prediction for other players.
    The SendToNonOwner is important to make sure you do not receive your own inputs and overwrite your inputs with a copy that is RTT old.
     
  4. Kichang-Kim

    Kichang-Kim

    Joined:
    Oct 19, 2010
    Posts:
    1,011
    @timjohansson If the scene has "moving platform" which player character can stand on, should platform object be marked as "Predicted"? (supposed platform's position can be predicted without any input)
     
  5. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    I actually was just now implementing networked moving platforms in my project, and I had the same idea. My platforms being "Predicted", and moving independently based on time, means that they'll be part of the prediction updates even though they have nothing to do with player commands. I think that makes sense
     
    Kichang-Kim likes this.
  6. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    It depends on what you want the moving platform to do. If it only supports the player and other predicted objects it makes sense to just make it predicted.
    If you want interpolated ghosts (other players, pickups etc) to stand on the platform it will be really hard to make that look good when the platform is predicted.
    If you need to support both predicted and interpolated on the platform I would probably lean towards setting up a transform hierarchy so objects on the platform have transforms relative to it - but it will still be a lot of work to tweak it and get the transitions really smooth.
     
  7. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    Could this be a good use case for synchronizing commands of every player across all clients, and making sure all the characters and movingplatforms are fully predicted by everyone?

    I imagine it would essentially be the same end result as having full world rollback/prediction but I haven't looked into it enough to be sure
     
  8. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    It might, but that depends on your game. Predicting remote players will be more expensive than having them interpolated - so if you have lots of players or are on a tight CPU budget it is probably not something you want to do. The remote players will also have a delay for the inputs and will most of the time predict using inputs which are a few frames old. If your movement is very twitchy and supports instant velocity changes this can look strange and introduce large prediction errors.

    If you want to try it out it's possible to do with netcode 0.6, you need to set your ghost prefab to predicted instead of owner predicted, make sure the CommandData is attached to the ghost, add [GhostField] to all fields - including Tick - in the command data struct you use for inputs and finally mark the command data struct with [GhostComponent(OwnerSendType = SendToOwnerType.SendToNonOwner)] to make sure the server is not sending back your own inputs and overwrites them with several frame old data.
     
    NotaNaN and PhilSA like this.
  9. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    260
    @timjohansson I have a case where there are entities that I need to predicted some of the time, but can be interpolated most of the time.

    The use case I have for this is vehicles. If a non player character or a non local player is controlling the vehicle then it is fine to allow it to be interpolated, but if a local player is controlling the vehicle then it should be predicted.

    A way to achieve this is to have the server spawn a predicted variant of this sort of entity and an interpolated variant of this sort of entity that can be swapped out depending on which behavior is required. The server would enable / disable a variant of the entity based on the required behavior. The animation / rendering of said entity would be separate from the predicted and interpolated variants and would follow whichever of these entities is in use at a given time. One of the disadvantages of this approach is that some of the data between the predicted and interpolated variants would have to be copied between the two entities when there use is swapped.

    Is there an easy way to do this?
     
  10. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    There is no easy way to do this right now. We are planning to investigate switching a ghost between interpolated and predicted on the client. I think we will add / remove the components specific to interpolated / predicted to make the switch entirely on the client without any involvement from the server - but that might change once we start investigating. Another complexity is that interpolated ghosts are behind the server in time while predicted are ahead of the server in time - so making a smooth transition for the required "time jump" is a challenge.
    This is not something we have started working on yet - and I don't know when we will start working on it.