Search Unity

Bug Cannot nest aspect with RefRW and EnabledRefRW to same component type

Discussion in 'Entity Component System' started by scottjdaley, Jun 7, 2023.

  1. scottjdaley

    scottjdaley

    Joined:
    Aug 1, 2013
    Posts:
    163
    Reposting this from my post in the Discord server:

    Not sure when if became possible, but it looks like we are now able to have both a RefRW and EnabledRefRW field for the same component type in an aspect (thank you!). However, nesting this aspect inside of another aspect results in a source gen error.

    Here is some example code:
    Code (CSharp):
    1. public struct MyComp : IComponentData, IEnableableComponent
    2. {
    3.     public float Value;
    4. }
    5.  
    6. public readonly partial struct InnerAspect : IAspect
    7. {
    8.     private readonly RefRW<MyComp> _data;
    9.     private readonly EnabledRefRW<MyComp> _enabled;
    10. }
    11.  
    12. public readonly partial struct OuterAspect : IAspect
    13. {
    14.     private readonly InnerAspect _inner;
    15. }
    And here is the error it generates:
    Unity.Entities.SourceGen.AspectGenerator\Unity.Entities.SourceGen.Aspect.AspectGenerator\Test__Aspect_8699727920.g.cs(277,5): error CS1503: Argument 2: cannot convert from 'Unity.Entities.RefRW<Test.MyComp>' to 'Unity.Entities.EnabledRefRW<Test.MyComp>'


    It appears to fail when generating the constructor for the outer aspect:
    Code (CSharp):
    1.  
    2.         /// <summary>
    3.         /// Construct an instance of the enclosing aspect from all required data references.
    4.         /// </summary>
    5.         public OuterAspect(global::Unity.Entities.RefRW<global::Test.MyComp> outeraspect_inneraspect__dataRef,
    6.             global::Unity.Entities.EnabledRefRW<global::Test.MyComp> outeraspect_inneraspect__dataEnref)
    7.         {
    8.             this._inner = new global::Test.InnerAspect(outeraspect_inneraspect__dataRef,
    9.                 outeraspect_inneraspect__dataRef);
    10.         }
    It is passing the
    dataRef
    parameter as both the data and enabled bit parameter of the inner aspect constructor.
     
    raweber and erenaydin like this.
  2. Kemorno

    Kemorno

    Joined:
    Apr 5, 2017
    Posts:
    20
    UP. Just came across this bug and saw no other thread or bug report besides this one...
    It seems like the second
    outeraspect_inneraspect__dataRef
    should be
    outeraspect_inneraspect__dataEnref
    to match the aspect's ctor

    Code (CSharp):
    1.             this._inner = new global::Test.InnerAspect(outeraspect_inneraspect__dataRef,
    2.                 outeraspect_inneraspect__dataEnref);
    3.  
    tried to edit it on the codegen generated file but it just generated a new one so i'm not able to confirm if this would fix it