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

Bug NetCode LinkedEntities with same Components causes badly generated code

Discussion in 'NetCode for ECS' started by Jawsarn, May 25, 2020.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Having a Ghosts with linked entities that has the same component (and one marked as ghostfield) will cause badly generated code in the TGhostSerializer, as multiple GetComponentDataFromEntity with the same type will be used. (caused InvalidProgramException: Passing an argument of size '10032'.)
     
    florianhanke likes this.
  2. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    @Jawsarn How did you resolve this issue? I may have the same error message, although I never had an issue due to what you describe (however, the multiple GetComponentDataFromEntity<SameT> are pointless).
     
    Stroustrup likes this.
  3. Stroustrup

    Stroustrup

    Joined:
    May 18, 2020
    Posts:
    142
    what did you put in place of the badly generated code?
    also my ghosts are just plain prefabs, not sure what you mean by linked entity.
    i just get this error when i go over 10 ghosts
     
  4. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    @florianhanke @Stroustrup So I haven't really resolved this in any good way, but waiting for a fix from unitys side. Currently I go in and manually fix the serializes. I've been away for a while, so not sure if there is any fix yet.
     
    florianhanke likes this.
  5. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    I see that they haven't fixed this yet. And saw that they had closed the issue on github with response of

    "... Recently we've been working on rewriting CodeGen for ghosting, so I'm closing this issue as should be fixed in the upcoming versions (the one which will be public after "0.3.1-preview.4").
    ..."
     
    Lukas_Kastern and florianhanke like this.
  6. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    @Jawsarn Thanks for getting back to us. I generate my Ghosts automatically, and I "solved" it by removing all Translation/Rotation components of children that are attached to the parent entity (thus reducing the size). My biggest problem currently is that I have to replace all [NativeDisableContainerSafetyRestriction] with [NativeDisableParallelForRestriction] whenever I regenerate the Ghost code, which is often, for Unity not to hard crash. I'm quite worried that a fix will not come soon, since the NetCode release cycles are rather large.
     
    Jawsarn likes this.
  7. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    You can replace them directly inside the CodeGenTemplate from which the serializer does get generated if you have NetCode added as a local package.

    The Template is located under com.unity.netcode@0.2.0-preview.5\Editor\CodeGenTemplates\GhostSerializer.cs
     
    Jawsarn and florianhanke like this.
  8. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Thanks for the reminder! :)
     
    Jawsarn and Lukas_Kastern like this.
  9. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    @florianhanke Nice that you could solve it by removing some components. I once asked regarding FPS sample if it was better as they did to group up data into components which are sent, or keep it grouped with functionality, and they said it should be better with functionality. But now in my case I have components with some data that is sent, and some that is local, and 24 different ghost types. So I'm a bit of a icky situation how I can solve this. Should I refactor components to only contain sent data & local? Set the project on hold until new netcode update?
     
    florianhanke likes this.
  10. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Apologies if this is a silly question: why does it matter how the sent fields are grouped into components when – in the generated code – they are "mushed" together anyway? I have only 8 ghost types, but I expect to have around 40, with quite a few components whose set of fields is only partially sent.
     
    Lukas_Kastern likes this.
  11. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    @florianhanke No you are very much correct in that it didn't make any difference if you add more local variables to the components, silly me. But if you combine sent fields into components you get less fields of ComponentDataFromEntity<T> which reduces the risk you will bump into this bug. So if you end up with your 40 ghost types before the update, I think you'll hit the problem again.
     
    florianhanke and Lukas_Kastern like this.
  12. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    Jawsarn and florianhanke like this.
  13. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    That helped me as well, thanks again, and I also was trying to reduce the amount of generated (and run, and also useless) code. Let’s hope for a close 0.3.0.
     
    Last edited: Aug 5, 2020
    Jawsarn and Lukas_Kastern like this.
  14. Stroustrup

    Stroustrup

    Joined:
    May 18, 2020
    Posts:
    142


    unity sure do like their #region statements
    what's the point of collapsing a line of size 1?
     

    Attached Files:

    Last edited: Aug 6, 2020
    bb8_1 likes this.
  15. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    Regions inside the NetCode codegen are marking the beginning and end of fragments.

    So when generating code you call GenerateFragment which copies the content of the region into the file.

    All of those __Whatever_Identifier__ inside the region do get used as keys for the dictionary that you pass into the GenerateFragment method, the identifier will than just be replaced with the value inside the dictionary
    .
    The codegen for NetCode is pretty solid.
     
    Last edited: Aug 6, 2020
    bb8_1, Jawsarn and florianhanke like this.
  16. Stroustrup

    Stroustrup

    Joined:
    May 18, 2020
    Posts:
    142
    it's very neat, i wish they would release a quick patch a day after a breaking issue like this is spotted though
     
    bb8_1, Jawsarn and Lukas_Kastern like this.
  17. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Me too. I get the impression some Unity dev teams don't make heavy use of the latest methodologies like automated integration etc. testing and CI/CD. If they were, then we'd see shorter release cycles. To be fair, it's probably not too easy either. But yeah, it's sometimes a bit tough going from N releases a day with thousands of tests in my professional environment to waiting weeks for a Unity package.
    Anyway, I hope a goal for Unity is to get up to speed re automated testing (and dependency management, where they seem to invest some resources), especially in experimental code, as it makes the devs and the users' lives so much easier.
     
    Jawsarn and Lukas_Kastern like this.
  18. Lukas_Kastern

    Lukas_Kastern

    Joined:
    Aug 31, 2018
    Posts:
    97
    To be honest with the release cycles and iterations we see on NetCode it feels like the NetCode team is just lacking tons of resources. I mean four months is a giant release cycle for a preview package which is supposed to be the future of multiplayer in Unity. I feel like the devs should just put out hotfixes or minor features every two/three weeks. At least from my point of view that would build a lot more trust.
     
    Last edited: Aug 6, 2020
    bb8_1, florianhanke and Jawsarn like this.
  19. florianhanke

    florianhanke

    Joined:
    Jun 8, 2018
    Posts:
    426
    Yes, I'd very much prefer a 2 week release cycle where even one release is buggy, I know I can just go back to the second most recent release and wait another two weeks. (I'd also already be happy with the current cycles, but with minor releases in between for fixes)
     
    Jawsarn, bb8_1 and Lukas_Kastern like this.
  20. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    We stumbled upon the same kind of issue for our DOTS project but for a different use-case (not using Unitys Netcode). Not to I just thought I'd add the knowledge I gained from the error when working with it if anyone else finds this thread when searching for information about this Exception:
    InvalidProgramException: Passing an argument of size '10032'

    The main problem was that our job struct simple became too large, as we were including TypeHandles for a ton of components (I believe it was somewhere around 150 TypeHandles). When the job struct eventually reached somewhere around 10k bytes, this error began throwing. We will solve it by rewriting our code to not create massive job structs, instead creating a ton of smaller jobs.