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

error DCICE001 Cant track it down , anyone know what causing this

Discussion in 'Entity Component System' started by RoughSpaghetti3211, May 10, 2020.

  1. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,697
    error DCICE001: Entities.ForEach Lambda expression uses something from its outer class. This is not supported. Seeing this error indicates a bug in the dots compiler. We'd appreciate a bug report (About->Report a Bug...). Thnx! <3


    EDIT :

    Narrowed it down to this system still not sure why there is a problem here
    Code (CSharp):
    1.    
    2.  public class PlanetCameraSystem : SystemBase
    3.     {
    4.         public float3 CameraLastPosition;
    5.         public float3 CameraNewPosition;
    6.        
    7.         protected override void OnUpdate()
    8.         {
    9.            
    10.             // Get current camera position
    11.             Entities.WithName("Job_GetCameraPosition").WithAny<PlanetCameraMainComponents>().ForEach((in LocalToWorld t) =>
    12.             {
    13.                 CameraNewPosition = t.Position;
    14.                
    15.             }).Run();
    16.            
    17.            
    18.         }
    19.     }
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,753
    Error is pretty straight forward, you are writing to the PlanetCameraSystem class variable CameraNewPosition which is not allowed. You can't capture the class in a job.
     
  3. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,697
    The error give me the impression that this should be possible. I keep reading that the Entities lambdas are special and with no CG etc so im never really sure what it can and cant do.
     
  4. Cell-i-Zenit

    Cell-i-Zenit

    Joined:
    Mar 11, 2016
    Posts:
    290
    you cannot get data out of the lambda like this..

    you first need to create a nativearray, then inside the foreach write into it, and afterwards access the data inside the array
     
  5. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    We will need to fix that error. In this case it isn't a DOTS compiler error, though it is correctly indicating that you need to make sure you are accessing the field as a captured local variable instead of something on the owning system (since it will be burst compiled in this case).

    The following code should work for your purpose (the variable will be captured, written to a field on the job and then the field will get copied out to the captured "savedPosition" local variable once the Entities.ForEach finishes running:

    Code (CSharp):
    1. public class PlanetCameraSystem : SystemBase
    2. {
    3.     public float3 CameraLastPosition;
    4.     public float3 CameraNewPosition;
    5.  
    6.     protected override void OnUpdate()
    7.     {
    8.         // Get current camera position
    9.         float3 savedPosition = new float3();
    10.         Entities.WithName("Job_GetCameraPosition").WithAny<PlanetCameraMainComponents>().ForEach((in LocalToWorld t) =>
    11.         {
    12.              savedPosition = t.Position;
    13.         }).Run();
    14.         CameraNewPosition = savedPosition;
    15.     }
    16. }
    I'll make sure we fix that error message so that it correctly indicates that the issue is with storing into a field of the system.
     
  6. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    Also, in this case it might make more sense to just use a singleton component since that code wouldn't make much sense if you had multiple components of that type.