Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Netcode and Interpolated Synchronized Component on a Predicted Entity

Discussion in 'DOTS Dev Blitz Day 2022 - Q&A' started by Kmsxkuse, Dec 7, 2022.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    305
    Am I correct in assuming that if I put a synchronized ghost component on a predicted entity, like the local player, and only read from it, the values within that ghost component will be the interpolated values from the server?

    Basically the predicted player entity will have a ghost component with a float value. That float value will only be written on the server and read on the client. Will the results of that float using the parameters Clamp and not InterpolateAndExtrapolate be values that are most recently received from the server?
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    882
    No. predicted ghost does not interpolate ghost fields. They are updated as part of the prediction loop and all the replicated component are usually updated there. The value is just and always Clamped to the last received form the server.
    The Interpolate and InterpolateExtrapolate only apply for interpolated ghosts.
     
    Kmsxkuse likes this.
  3. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    306
    It depends. Your ghost is predicted, so it'll run all prediction code on the client. If you have prediction code that writes to your custom ghost component, your client is predicting those values.

    You'd only achieve your desired behaviour if the code that writes to the component is entirely outside the prediciton loop. But note: Ensure your prediction code doesn't read it, otherwise your client will be constantly miss-predicting.


    Yeah, Clamp ensures that the value will jump straight to the latest value, when a snapshot is received.
    Note though: When predicting an entity, `SmoothingAction.Clamp` is forced. `Interpolate` and `InterpolateAndExtrapolate` are only useful with Interpolated Ghosts.
     
    Kmsxkuse likes this.