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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Will it ever be possible to write to an EntityCommandBuffer from an ISystem?

Discussion in 'Entity Component System' started by PublicEnumE, May 7, 2022.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Is writing to an ECB from a bursted ISystem.OnUpdate() planned to ever be supported?

    In another thread, @cort_of_unity commented about how ISystem might be thought of/developed in the future: https://forum.unity.com/threads/com...nent-doesnt-use-m_cache.1270037/#post-8098550

    I've been working to see how much I can use ISystem in my code. Unity has been clear that ISystem is still not ready for prime time. But I tend to use some of the basic job types (IJobChunk, and the "BurstSchedulable" set) . So I figured, why not see what's possible.

    I was surprised that I could use them for nearly everything. And the bursted system code has led to some big speed-ups in my case. It's exciting stuff!

    The main thing holding me back right now, is the inability to write to ECBs from ISystems:
    1. ISystems can't interact with managed ECBSystems.
    2. I can't seem to create and dispose of a single, Persistent ECB in an ISystem. I get an unallocated Native Collection error, each frame (are Persistent allocators not supported for ECBs?)
    3. I can't create an ECB inside of ISystem.OnUpdate(), since the ECB constructor references non-readonly static data.
    I'm wondering if writing to an ECB from an ISystem is ever expected to be supported in the future.

    I'm not expecting to be able to play back an ECB in bursted code, but writing to them (for playback in a non-bursted system later) would open up a lot of possibilities.

    Thanks for any info!
     
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,993
    From what I have gathered, the plan is to support NativeContainers being stored in unmanaged memory, which would let us store them in ISystem and allow ECB to be written as ISystem. So it is definitely planned, but requires engine changes that seem to be coming in the 2022 releases.

    As for ECB not working in OnUpdate, I'm not sure what its deal is. But I was able to get my custom command buffers to be created, populated, and played back all within a Bursted ISystem's OnUpdate. https://github.com/Dreaming381/lsss...SubSystems/Gameplay/SpawnShipsEnableSystem.cs
     
  3. cort_of_unity

    cort_of_unity

    Unity Technologies

    Joined:
    Aug 15, 2018
    Posts:
    97
    You have successfully identified some of the reasons we have indicated that ISystem is not yet ready for prime time :) The good news is that yes, we have full support for recording and playing back EntityCommandBuffers in Burst-compiled ISystems working internally, ready for the next big release.
     
    bb8_1, MNNoxMortem, DrBoum and 7 others like this.