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

Resolved Exception "Burst Error BC1016" Caused by state.World.CreateSystem<T>()

Discussion in 'Entity Component System' started by layker90524, Aug 18, 2023.

  1. layker90524

    layker90524

    Joined:
    Nov 13, 2022
    Posts:
    9
    I encountered this exception:
    Burst error BC1016: The managed function `Unity.Entities.SystemState.get_World(Unity.Entities.SystemState* this)` is not supported
    while using
    state.World.CreateSystem<MySystemGroup>()
    in my ISystem's OnUpdate method.

    It only shows up after the editor has recompiled the scripts and can be resolved by not using the "BurstCompile" attribute on the method.

    These are sample codes:
    Code (CSharp):
    1.  
    2. [UpdateInGroup(typeof(GameSystemGroup))]
    3. public partial struct MyOtherSystem : ISystem
    4. {
    5.     [BurstCompile]
    6.     public void OnUpdate(ref SystemState state)
    7.     {
    8.         ......
    9.         state.World.CreateSystem<GameWorldSystemGroup>();
    10.         ......
    11.        
    12.        state.Enabled = false;
    13.     }
    14. ......
    Code (CSharp):
    1. [DisableAutoCreation]
    2. public partial class GameWorldSystemGroup : ComponentSystemGroup
    3. {
    4.     protected override void OnCreate()
    5.     {
    6.         base.OnCreate();
    7.  
    8.         World.GetExistingSystemManaged<GameSystemGroup>().AddSystemToUpdateList(SystemHandle);
    9.  
    10.         AddSystemToUpdateList(World.CreateSystem<MySystemOne>());
    11.         AddSystemToUpdateList(World.CreateSystem<MySystemTwo>());
    12.         AddSystemToUpdateList(World.CreateSystem<MySystemThree>());
    13.     }
    14. }
    Is this the correct way to create a SystemGroup and the ISystems it includes?
    And is the lack of support for Burst an unavoidable side effect?


    Additionally, I am using the Rider IDE, and I noticed that the code "state.World" has a warning (yellow squiggly underline) with the hint:
    Burst: Loading managed type 'World' is not supported
    This warning only appears for about 1 second when I change any code in the same file. I have to move the cursor over it within that 1-second window to check the hint, or it will disappear until the next time I change the code, as if there is no problem.

    I think this disappearing behavior is a bug?
     
    Last edited: Aug 18, 2023
  2. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    288
    The hint is correct. `World` is a managed type. Primary rule: you can't use/access managed objects it inside Bursted code.

    AFAIK, this is wrong, you're not supposed to do this in an ISystem or SystemBase.

    You would want to look at ICustomBootstrap. And inspect the code of
    DefaultWorldInitialization.Initialize
    .
     
    Last edited: Aug 19, 2023
    layker90524 likes this.