Search Unity

Question Entities 1.0 migration questions

Discussion in 'Entity Component System' started by azmi_unity, Mar 20, 2023.

  1. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    I'm in the midst of migrating from Entities 0.3x and 1.0 is quite different from what I'm used to. Appreciate if someone could answer these:

    1. It's mentioned that OnCreate, OnDestroy has to be implemented even if empty on ISystem. But it seemed to work fine without them. Are these still needed?

    2. [BurstCompile] is needed for ISystem callbacks methods, but not needed for IJobEntity Execute() method?

    3. What's the difference between [WithAbsent] and [WithNone]?

    4. Is it safe now to use native collections as fields inside IComponentData or ICleanupComponentData?

    5. What's the best way to share data between ISystems (in the main thread): GetUnsafeSystemRef() or using a singleton?

    6. Any NativeHashMap equivalent for DynamicBuffer?

    7. In the editor, objects in an "open" subscene don't seem to reset back to their original positions after play mode. Is this intended?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    > 1. It's mentioned that OnCreate, OnDestroy has to be implemented even if empty on ISystem. But it seemed to work fine without them. Are these still needed?

    pre 44 added default interface implementations so they aren't required

    > 2. [BurstCompile] is needed for ISystem callbacks methods, but not needed for IJobEntity Execute() method?

    Correct. Burst has never been required for a jobs Execute method only on the struct.
    https://forum.unity.com/threads/whe...with-mild-under-the-hood-explanation.1344539/

    > 4. Is it safe now to use native collections as fields inside IComponentData or ICleanupComponentData?

    Hmm you can't query a component with a native container. The only good use case of native containers on components is on singletons where you query the singleton in a system then pass the container into the system

    > 5. What's the best way to share data between ISystems (in the main thread): GetUnsafeSystemRef() or using a singleton?

    Entities singleton pattern would be the standard way.

    > 6. Any NativeHashMap equivalent for DynamicBuffer?

    Not officially. I actually wrote a kind of wrapper for DynamicBuffer that turns it into a DynamicHashMap and DynamicMultiHashMap https://gitlab.com/tertle/com.bovinelabs.core/-/tree/master/BovineLabs.Core/Iterators
    Maybe something to inspire
     
    NOTT and Sirius64 like this.
  3. azmi_unity

    azmi_unity

    Joined:
    Dec 13, 2020
    Posts:
    62
    Thank you! If you don't mind, I've a few more...

    I also noticed IJobEntity seem to get scheduled even if there aren't any matching entities. Is it better to wrap them with
    if (!entityQuery.IsEmpty) 
    ?

    Is ecb.CreateCommandBuffer(state.WorldUnmanaged) reusable across multiple jobs?
     
  4. omg_peter

    omg_peter

    Joined:
    Dec 7, 2020
    Posts:
    11
    > 3. What's the difference between [WithAbsent] and [WithNone]?

    It took me a bit to find the answer to this but I found one over here: https://docs.unity3d.com/Packages/c...ity_Entities_EntityQueryBuilder_WithAbsent__1
    • WithAbsent<T>() matches all entities in chunks that do not have T at all.
    • WithDisabled<T>() matches chunks that must have T, but only matches entities where T is disabled.
    • WithNone<T>() matches both of the above cases: either the component isn't present at all, or it is present but disabled.
     
    micha_dev, NOTT and elliotc-unity like this.