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

Bug Advanced use case ISystem codegen bugs

Discussion in 'Entity Component System' started by DreamingImLatios, Oct 17, 2022.

  1. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    This weekend, I finally got to take advantage of collections being unmanaged and migrated some of my custom command buffer and collection dependency tracking tech to work in Bursted unmanaged systems. Almost everything is working correctly, but I did come across a few surprise bugs.

    Bug 1: Discard in idiomatic foreach
    Code (CSharp):
    1. // Broken
    2. foreach ((_, var entity) in Query<RefRO<Faction> >().WithEntityAccess().WithAll<FactionTag>())
    3. {
    4.     m_factionsCache.Add(latiosWorld.GetCollectionComponent<FactionShipsCollisionLayer>(entity, true));
    5.     factionEntities.Add(entity);
    6. }
    7.  
    8. // Works correctly
    9. foreach ((var unused, var entity) in Query<RefRO<Faction> >().WithEntityAccess().WithAll<FactionTag>())
    10. {
    11.     m_factionsCache.Add(latiosWorld.GetCollectionComponent<FactionShipsCollisionLayer>(entity, true));
    12.     factionEntities.Add(entity);
    13. }
    Bug 2: Concrete generic jobs aren't picked up by codegen for early init
    Two years ago, there was a hot topic on the forum revolving around the use of generic jobs. That ultimately lead to this repo: https://github.com/Dreaming381/BurstGenericsTest

    Anyways, I have been using this pattern since, and it has always worked, except when I tried to use it inside a Burst ISystem. Bug report is IN-19950. If you want a working version of the project, you can find it here, linked to the exact line where I had to comment out [BurstCompile] for one of the systems that was reliant on this pattern: https://github.com/Dreaming381/lsss...tems/Gameplay/ShipVsBulletDamageSystem.cs#L32

    Note, the bug report made a mention of another type handle warning issue. I just found the culprit and it is my fault, so ignore that.
     
  2. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    85
    The first one has been logged as a bug and we are looking into it.

    I'm having trouble finding the ticket you logged for the second issue. Mind explaining your issue in a bit more detail (I'm not clear on how ShipVsBulletDamageSystem uses generic type arguments/parameters)?
     
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,983
    It happens at line 57. Physics.FindPairs is a generic method which in this case returns a FindPairsLayerLayerConfig<DamageHitShipsAndDestroyBulletsProcessor>. That struct contains a static class called FindPairsInternal. And FindPairsInternal contains a few jobs. The ones we care about here are LayerLayerPart1 and LayerLayerPart2_WithSafety. Those get scheduled back-to-back in ScheduleParallel().

    You can clone the project with the linked hash (the hash is the latest commit as I am writing this) and uncomment the [BurstCompile] line and see the error for yourself.