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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Right way to upgrade packages (e.g., netcode)? (All components break)

Discussion in 'NetCode for ECS' started by alvinwan, May 10, 2020.

  1. alvinwan

    alvinwan

    Joined:
    Jan 21, 2018
    Posts:
    34
    After updating to netcode 0.1, the netcode 0.1 tutorial code threw a number of errors. Per the netcode changelog, I made some fixes:
    • removed all `ref DataStreamReader.Context ctx`. (e.g., `reader.ReadInt(ref ctx)` -> `reader.ReadInt()`)
    • `writer.Write` -> `writer.WriteInt`.
    • Added `ref` to all `DataStreamWriter` args
    However, after upgrading, all of my components break (pictured in 'spoiler' below)


    Perhaps I'm not correctly updating packages? i.e., Maybe the ordering is wrong: I upgraded NetCode to 0.1, Entities to 0.8, then sequentially upgraded packages with broken dependencies. Here are my current package versions ('spoiler' below):

    • Burst: preview.7 - 1.3.0
    • Collections: preview.2 - 0.7.0
    • Entities: preview.8 - 0.8.0
    • Havoc: preview - 0.2.1
    • Hybrid Renderer: preview.24 - 0.3.4
    • Jobs: preview.11 - 0.2.7
    • NetCode: preview.6 - 0.1.0
    • Unity Physics: preview-0.3.1
    • Unity Transport: preview.6 - 0.3.0

    Even the super simple components (GrassComponent, below) break. Is there a right ordering of packages to update? Or are my components just now "wrong"? (It seems like GenerateAuthoringComponent is still valid per the Entities changelog.)

    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [GenerateAuthoringComponent]
    4. public struct GrassComponent : IComponentData
    5. {
    6. }
    Code (CSharp):
    1. using Unity.Entities;
    2. using Unity.Mathematics;
    3. using Unity.NetCode;
    4.  
    5. [GenerateAuthoringComponent]
    6. public struct HoldableComponent : IComponentData
    7. {
    8.     [GhostDefaultField]
    9.     public Entity HolderEntity;
    10.     public bool HolderNeedsHoldableSet;
    11.     public float3 Position;
    12. }
     
  2. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    What are the errors?
     
  3. alvinwan

    alvinwan

    Joined:
    Jan 21, 2018
    Posts:
    34
    Here's the one error that persists: "'PlayerSnapshotData' does not contain a definition for 'Get'"

    Code (CSharp):
    1. Assets/Scripts/Characters/Generated/PlayerGhostUpdateSystem.cs(237,63): error CS1061: 'PlayerSnapshotData' does not contain a definition for 'Get' and no accessible extension method 'Get' accepting a first argument of type 'PlayerSnapshotData' could be found (are you missing a using directive or an assembly reference?)
    1. I assume this means I need to regenerate the ghost authored scripts
    2. Generation fails, because components cannot be found e.g., "Could not find the type AttackComponent".
    3. I tried re-adding all components. However, my components aren't discoverable via "Add Components".
    4. This also applies to newly-created ones: I added a TestComponent, but it's not discoverable (TestComponent.cs below).
    Code (CSharp):
    1. using Unity.Entities;
    2.  
    3. [GenerateAuthoringComponent]
    4. public struct TestComponent : IComponentData
    5. {
    6. }

    So I've hit a wall here. @florianhanke Any pointers for what to investigate would be greatly appreciated. Perhaps I could diff my list of package versions with yours? I've attached mine, if you'd like to see.


    *At some point during the upgrade process, I'd also get the following error: "itGuid != guidMap.end()". After closing and reopening Unity, this error went away.

    *To ensure my code's correctness, I reverted the project to Entities 0.5.0, NetCode 0.0.4 (and undid the networking changes), and the project works just fine. I'm on Unity 2020.1.0b7.
     
  4. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Your analysis seems fine to me – some people had issues with components not being findable. Can you take a look at TestComponentAuthoring in the DOTS > DOTS Compiler > Open Inspector...? Or perhaps write a manual conversion, and see if that helps.
     
    alvinwan likes this.
  5. Wobbers

    Wobbers

    Joined:
    Dec 31, 2017
    Posts:
    55
    As long as there are compiler errors in your project (like the Get error in PlayerSnapshotData) anything code generation might not work properly because the new code has not compiled yet and the code generation is still operating on the "old", before compilation code.
    I think this is also why your TestComponent is not visible in the editor or your other "script can not be loaded" problems. They are not compiled yet because of the compilation error preventing it, so unity doesn't know about them yet.

    So you should first get to a clean project state. If there are things in the old snapshotdata that is incompatible with the new netcode package, either comment these parts out or delete the file (and comment all other stuff out that references the file if that still causes compilation errors) until all compilation errors are gone. When the project recompiled with no errors you should be able to regenerate the ghosts.
     
    alvinwan likes this.
  6. alvinwan

    alvinwan

    Joined:
    Jan 21, 2018
    Posts:
    34
    Ahh thanks @florianhanke and @Wobbers! Many hours struggling but that finally fixed it: I got my project back into a clean state by commenting out, as suggested. Then, I was able to regenerate ghost code, and all the prefabs/components were restored with their original data.

    What a weird one. This is a good quirk to remember, thanks again.
     
  7. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    944
    That is an issue I encountered when trying to make some custom system. It used heavily code generation but due to the dependency between the "normal" code base and the generated code base it made changing anything that was remotly linked to the generated code a nightmare as thing could not compile. This made me move away quickly from code generation.

    Not sure if a scalable netcode package cna be pull of if it use lot of code generation.
     
  8. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Good point, @Wobbers – I completely forgot about simply removing the generated files. When working on NetCode, before generating, I checked in the current state with git, and if I needed to go back and re-generate from scratch, I just ran `git reset hard` and ran generation again.