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 0.50 beware of strict namespace restriction.

Discussion in 'Entity Component System' started by alexandre-fiset, Mar 18, 2022.

  1. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    702
    This code won't compile on DOTS 0.50:

    Code (CSharp):
    1. using Unity.Entities;
    2. namespace MyNamespace.System
    3. {
    4.     public partial class BrokenSystem : SystemBase
    5.     {
    6.         protected override void OnUpdate()
    7.         {
    8.             Entities.ForEach((MyComponent c) => {}).Run();
    9.         }
    10.     }
    11.     public struct MyComponent : IComponentData { }
    12. }
    13.  
    Beware that in a big project this can be quite a nightmare. It means that if you have something like Views.Interaction and Player.Interaction, with a foreach referring both, codegen will break.

    The only workaround I found was to give unique names to my namespaces and never use System in any part of the namespace.

    Case 1411801
     
    Last edited: Mar 18, 2022
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Hmm I have about 100 different variations of BovineLabs.X.Systems or Data etc namespaces and have no issue compiling.

    My differences are
    - Plural though, I have no System namespace.
    - Also my using are within the namespace if that makes a difference
     
  3. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    702
    Plural will work because it doesn't clash with System. And the second might be a viable long term workaround if this behaviour is by design. Still, that's how Rider and VS functions (putting usings at top of the file, outside namespace).

    The bug can be reproduced in an empty project by simply doing a ForEach inside a namespace containing System. That could be My.System.Something or Something.System, as long as System is somewhere, it will break codegen.
     
  4. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    258
    I had this issue as well with the namespace
    EnvironmentRenderingSystem
    , but weirdly completely removing the entities package from the project and reinstalling it fixed the problem...