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

EntityCommandBuffer on Editor Mode

Discussion in 'Entity Component System' started by lmml, Jun 21, 2020.

  1. lmml

    lmml

    Joined:
    May 2, 2020
    Posts:
    6
    Hi there, I am trying to use a ECB (EntityCommandBuffer) while editor mode is activated , this is Play mode IS NOT

    I found a problem related to Update Func that i solved following this post last answer: https://forum.unity.com/threads/editor-scripting-with-ecs.527687/ cause I want to use ecb on Update and on editor mode as I said.

    I am not sure but probably it will be related to ecb system or something cause i checked that the update run but nothing happens

    Here is some code i wrote:

    Code (CSharp):
    1. if (!work)
    2.                 return;
    3.  
    4.             var ecb = _ecbSystem.CreateCommandBuffer().ToConcurrent();
    5.  
    6.             JobHandle j = Entities
    7.               .WithAll<workTag>()
    8.               .ForEach((int entityInQueryIndex, Entity entity) =>
    9.               {
    10.  
    11.  
    12.                   Entity aux_vertexSample = ecb.CreateEntity(entityInQueryIndex);
    13.                   ecb.AddComponent<ProjectedOccluder>(entityInQueryIndex,aux_vertexSample,new ProjectedOccluder { Occluder = entity });
    14.                   ecb.AddComponent<ProjectionVertex>(entityInQueryIndex, aux_vertexSample);
    15.  
    16.               })
    17.               .ScheduleParallel(Dependency);
    18.               _ecbSystem.AddJobHandleForProducer(j);
    19.  
    20.             j.Complete();
    21.  
    22.             work = false;
    Just a test so dont judge me :)
     
  2. lmml

    lmml

    Joined:
    May 2, 2020
    Posts:
    6
    Okey i just tried this before using the system
    Code (CSharp):
    1. EditorApplication.update -= () => world.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>().Update();
    It looks to work, i have to do more test but at least add the entities so i guess it works

    this is based on the post i said before on the top