Search Unity

Feature Request Request system update like server in GhostPredictionSystemGroup

Discussion in 'NetCode for ECS' started by optimise, Jun 10, 2021.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Hi @CMarastoni. Long time ago I believe @timjohansson mention before that making system in GhostPredictionSystemGroup update just like system in ServerSimulationSystemGroup i.e. update only 1 times per frame for owner predicted / predicted ghost is being working on. Currently it's called multiple times per frame which make it really hard to implement. Will this feature ship in next netcode 0.7 or later?
     
    Last edited: Jun 11, 2021
  2. NovaEiz

    NovaEiz

    Joined:
    Sep 6, 2017
    Posts:
    53
    On the server, it is updated 1 time. So it was and is now.
     
  3. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    894
    The prediction group run at fixed time step. As such:
    - on the server is run once per server tick
    - on the client is may run multiple time per simulation tick, depending on ration in between the simulation rate and you actual frame rate.
     
  4. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    What I mean is make it internally it still work like that but the system I create update in ghost prediction system group u make it only go in call only once per frame. I believe @timjohansson also mention something like that before.
     
  5. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    894
    No, I can be called multiple time per frame on the client. If you simulation run at 60hz but your game run at 30hz you run the simulation two times per frame.
    Also, the client run partial ticks, in case the frame rate is higher than the sim rate. Ex: If your sim is 60hz and your client runs a 75hz for example, the simulation may be called twice: once with a full sim delta time and once with a residual delta time less than the 16ms.
    What the ghost prediction group guarantee you is that the simulation is always starting from the last full predicted tick.
     
  6. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Maybe is this quote I dun quite remember but looks this quote is just mention making typing if (!GhostPredictionSystemGroup.ShouldPredict(tick, predictedGhostComponent)) return is not required anymore if I understand correctly. So, does it still mean it still called multiple time per frame on the client even this less typing feature is available in new version of Netcode package?
     
  7. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    894
    the GhostPredictionSystemGroup.ShouldPredict must be always called. In the future we are thinking to remove that completely but right now is mandatory to call.
    What Tim is saying is that this call make you sure you are running your system logic for the entities that need that tick to be predicted.
     
  8. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    @CMarastoni I would like to provide more contexts about the problem I face. I found that I always need to create a couple of bool components to make sure the logic in the system only run once instead of multiple times. If I don't do that at client it will not look and behave correctly although technically at the end after server rerun the system will get the same result. Is that expected or am I doing something wrong?
     
  9. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    894
    It is expected that the client may run the prediction logic multiple time with different delta time (because of the frame rate).
    If the client behave incorrectly, it may be that you are using inside you systems some components that are not replicated (or fields that are not replicated).
    Also, worth to remember: CLIENT SIDE PREDICTION is just a best effort approximation of the server behaviour in general. However, when condition apply, it should (or must, depending) give the same results.

    If you really need to run logic only once and you don't want to add extra component, you may try to investigate if using the ServerTickFraction can help.
    for example something like like:
    Code (CSharp):
    1.  
    2. ./..
    3. int m_lastPredictedTick = 0 (in the class)
    4.  
    5. if(!ShouldPredict(predictedTick) || (serverTickFraction < 1.0f && m_lastPredictedTick == predictedTick)
    6.    return
    7. ...
    8. m_lastPredictedTick = predictedTick;
    9.  
    The example will run the logic only if prediction is needed and it is a full simulation tick. There are some caveats though in relation to the fact the client try to catch up with the server and it may end up skipping one or more tick at the very beginning of the game.
     
  10. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    @CMarastoni Does it means that as long as I mark GhostField to the required components correctly I should get almost the same result at client without needing to create a couple of bool component to make logic run only once?