Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[NetCode] Client Side Prediction Questions

Discussion in 'NetCode for ECS' started by Flipps, Jan 21, 2020.

  1. Flipps


    Jul 30, 2019
    First of all, i really like the new DOTS Netcode. Its really easy to get things done, even though it is my first network game.

    The only part which is quite difficult to understand / implement is the client side prediction. Therefore i have some questions how things are ment to be done:

    1. Client side rollback always necessary?
    In the GDC talk from overwatch they mention that they only do a client side rollback if the snapshot mismatches with the prediction. Only in cases of miscalculation or player influence (like stuns) they apply the snapshot and run all inputs again.

    Are there any plans to only apply the snapshot if the prediction was wrong? Or do we have to implement this on our own?

    2. Replicate ComponentData
    It would be really nice to also synchronize the Component tags of a ghost entity. Especially useful when the state of a predicted entity gets rolled back and also the Component Tags have to be removed.
    Of course the componen tags should not be included in the matching archetype and an option has to be provided that does not attach them at start.
    At the moment i am handling this with a component sync system which manually adds/removes components.

    3. Physics in Prediction
    My game really does not need alot of complicated physics. The most part is moving projectiles and detecting collions / triggers. The character controller is made with the Physics SimplexSolver.
    I questioning how i should implement the physics prediction. I think there are two ways:

    1. Set Physics Velocity in the predicted ghosts and run the Physics Worlds (BuildPhysicsWorld/Step/Export) in the ghostpredictionsystemgroup. Detect collisions / triggers with implemented callbacks ICollisionEventJob.

    2. Calculate the translation/rotation directly and check collisions with OverlapAABB or Distance queries. I think i need to create the Collisionworld here, too.

    Method 2 seems way more efficient than building the complete Dynamic world (but just guessing).

    4. Send pure States from Client
    I know its against the concept of client side prediction, but are there any plans to send state directly from the client to the server? This can already be done by sending states in the CommandData and then dont send the snapshots back to the predicted client. Gets really messy if you want to send other entities like projectiles to the server.
    Maybe this would help some new guys like me to get into DOTS networking more easily.

    Thanks in advance
  2. timjohansson


    Unity Technologies

    Jul 13, 2016
    We do not have any short-term plans to do this, when using fixed tickrate on the client we only roll back after receiving new data from the server instead of every frame - and we will investigate doing something similar when we investigate smooth miss-prediction recovery (interpolate towards server pos instead of snapping). If you do add it yourself, keep in mind that it does not optimize the worst case - so you might need to take that into account when measuring performance, make sure to measure with some packet loss.

    We have a task on our backlog to investigate this. Currently we are considering supporting it by having "optional" components which will have their presence serialized as part of the snapshot - but that might change once we start implementing it.

    Physics support in prediction is currently not fully supported since the prediction is a loop over several frames and the physics runs after that loop. There is no easy way to move physics into the prediction loop, that is something we plan to investigate later. What we are doing in DotsSample is to use a character controller based on raycasts rather than physics simulation. Performing raycasts in the prediciton loops is possible.

    No, there are no plans to do that. You can implement it by including some state in the commands like you say, and for owner predicted ghosts it is possible to send different data to predicted and interpolated clients which should allow you to only send the data to interpolated.
    For projectiles specifically I would recommend using predictive spawning instead. You create the ghost on the client in a special way, and when you get a new ghost from the server you try to match it to the predicatively spawned client side ghost so ownership can be transferred instead of spawning a new object. See
    Flipps likes this.
  3. Flipps


    Jul 30, 2019
    Thanks for the really fast answers and great feedback!

    Nice to hear that this is on the task list

    Ok than i think the best way for predicted rockets is to check the collision by queries (like raycasts/OverlapAabb etc). Unfortunetly no bullet/rocket entities are used in DOTS Sample (only direct raycast). The Asteroid sample perfoms the collision only on server side by checking the intersection of the 2d radius. Maybe a chance to add an example of firing rockets to the DOTS Sample? :)

    Then i will try to investigate into the predictive spawning :)
    Mikael-H and Opeth001 like this.