Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question [1.0.0-exp.8] Breaking changes questions

Discussion in 'NetCode for ECS' started by optimise, Oct 12, 2022.

  1. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,032
    1) Both World.GetExistingSystem<GhostPredictionSystemGroup>().PredictingTick and
    World.GetExistingSystem<ServerSimulationSystemGroup>().ServerTick change to SystemAPI.GetSingleton<NetworkTime>().ServerTick?

    2) World.GetExistingSystem<GhostPredictionSystemGroup>().Time.DeltaTime change to SystemAPI.Time.DeltaTime?
     
  2. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    Hello @optimise,

    Very good question !

    Can you please share your manifest.json because i am struggling to migrated from 0.51 to 1.0 with all the dependencies.. ?
     
  3. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    That is what we used for the migration of our current netcode project and it worked as expected.

    Also don't forget to remove the checks to prediction and instead use the `WithAll(typeof(Simulate)`, which is a lot more pleasant than before.

    @Ali_Bakkal You just need to upgrade everything to 1.0, dependencies should be automatically handled. With what are you exactly struggling?
     
  4. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    Unity does not offer automatic upgrade, so i change directly the version inside of the manifest.json. And when i put : Entities, replace Hybrid by entites.graphics and Netcode to 1.0, i have dependency errors.. can you please send me a copy of your manifest.json in order to check all my dependencies..

    Thanks in advance
     
  5. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    If you can’t upgrade directly from the package manager it’s probably because you aren’t using the right unity version.

    Which unity version are you currently using in the project?
     
  6. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    I am using Unity 2020.3.30f1, which version should i use then ?
    (which is stable to build on Linux, Macos, Android and iOS)
     
  7. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    If you want to use 1.0.x you need to use 2022.2.x (currently in beta).

    otherwise you need to stay on 0.53
     
  8. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    (if you use netcode you currently can’t build for any platform, it’s a known issue and they are working on it)
     
  9. Ali_Bakkal

    Ali_Bakkal

    Joined:
    Jan 26, 2013
    Posts:
    84
    Ok Thank you @Occuros for your help !
     
  10. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,032
    Not really understand what u mean. Can u show me an example?
     
  11. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    781
    There is a full upgrade guide https://docs.unity3d.com/Packages/com.unity.netcode@1.0/changelog/CHANGELOG.html#upgrade-guide

    That tell you how to go from 0.51 to 1.0-exp.8.
    One missing details, sorry about it, regards the Simulate component.

    Systems that run in the prediction loop and there need to update the state of the Predicted ghost (or in general have to deal with ghosts), must add to their queries the
    Code (csharp):
    1. WithAll<Simulate>()
    clause.

    For example:
    Code (csharp):
    1.  
    2. Entities.WithAll<Simulate>().ForEach(.....)...
    3. //or with Idiomatic foreach
    4. foreach(... in SystemAPI.Query<...>().WithAll<Simulate>)
    5.  
     
  12. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,032
    Do u mean when u the system is at PredictedSimulationSystemGroup and you are updating owner predicted/predicted ghost, you need to put WithAll<Simulate>() into the ghost? Btw then do we still need to call predictedghost.ShouldPredict() from PredictedGhostComponent just like at 0.51?
     
  13. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    781
    All entities now have an enableable Simulate component tag (by default).

    You don't need to check for the ShouldPredict anymore.

    instead,
    your queries need to check for the presence of the Simulate component. That it.

    So before was:

    Code (csharp):
    1.  
    2. Entities.Foreach(Entity ent, ref MyCompo compo, in PredictedGhostComponent component)=>
    3. {
    4.     if(!PredictedSimulationSystemGroup.ShouldPredict(component))
    5.          return;
    6. })
    7.  
    Now, there is no need to get the PredictedSimulationSystemGroup anymore and the loop become
    Code (csharp):
    1.  
    2. Entities.WithAll<Simulate>().Foreach(Entity ent, ref MyCompo compo)=>
    3. {
    4.     if(!PredictedSimulationSystemGroup.ShouldPredict(component))
    5.          return;
    6. })
    7.  
    The prediction loop take care of enabling/disabling the simulate tag as necessary during the loop for you.
     
    Occuros likes this.
  14. Occuros

    Occuros

    Joined:
    Sep 4, 2018
    Posts:
    284
    There is also now a different way how you can handle inputs.

    No more Tick is required, and events are supported (so you can be sure that jump button gets processed):

    Code (CSharp):
    1. public struct PlayerInput : IInputComponentData
    2. {
    3.     public int Horizontal;
    4.     public int Vertical;
    5.     public InputEvent Jump;
    6. }
    So it is no more a buffer, but you get the correct input for the frame you are processing in the prediction.

    The documentation is a little problematic as it still uses the previous way in the `GettingStarted` section, and in the `Command Stream` section, it still uses the deprecated `GenerateAuthoringComponent` attribute.

    But if you use the bakers instead the `Command Stream` section should be up to date (I think correct @CMarastoni ?)


    At least we managed to get our project fully up and running in the editor.
     
  15. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    781
    you can still use the old Command Buffer way if you want. If you use the IInputComponentData then you just need to grab the component itself (that is guarantee to have the correct tick information in the prediction loop).
    Under the hood everything will be automatically be baked, a command buffer will be added to the entity. But you should not care about it.
     
  16. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,032
    I see but currently I have a lot of systems at PredictedSimulationSystemGroup still using predictedGhostComponent.ShouldPredicted(). Can I still keep it first until I have time to upgrade to this new way? Btw if I understand correctly, seems like there's typo for code snippet. I guess new way should like that right?

    Code (csharp):
    1.  
    2. Entities.WithAll<Simulate>().Foreach(Entity ent, ref MyCompo compo)=>
    3. {
    4.  
    5. })
    6.  
     
  17. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    781
    Yes probably there was a typo :)
    You can still use the old way if you wish (it still work) In the end, we use the ShouldPredict method internally.
     
    optimise likes this.
  18. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,032
    For my old Command Buffer way I put
    One more question want to confirm about this. Will this WithAll<Simulate>() without if PredictedSimulationSystemGroup.ShouldPredict(component) check still working properly if it's query the child ghost entity of owner predicted/predicted ghost? This child ghost entity is part of the owner predicted/predicted ghost that is child of it that u can fold/unfold at Entities Hierarchy window. From what I see child ghost entity also have Simulate tag component.
     
  19. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Yes, the simulate tag will be updated on all entities in the LinkedEntityGroup of the ghost, so everything in the ghost prefab will be updated.
    It will not work for transform hierarchies which are not using the same LinkedEntityGroup though - and I am not sure if the Hierarchy window shows linked entity groups of transform hierarchies so I don't know if checking there is the right way to see if it will be updated.
     
    Occuros likes this.