Search Unity

[Help] How to enqueue entities?

Discussion in 'Entity Component System' started by georgeq, Mar 11, 2020.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I have this problem:

    I need to write a system which can process the first and only the first element of a list of entities. Once the first entity in the list is found, it has to be moved to another position on screen, and then placed it back in the list as the last element, very much like a queue. Obviously, since order is a key factor for this system, I cannot just create an entity query and grab the first element.

    The easiest way to implement this system would be to store my entities on a NativeArray<Entity>, but since Entity is not blittable I cannot store it on an IComponentData. I could however store it on a MonoBehaviour, but that feels like a lame, shameful solution.
     
  2. Soaryn

    Soaryn

    Joined:
    Apr 17, 2015
    Posts:
    328
    Um... Entity is blittable and can be stored in an IComponentData. I do it all the time? it is purely an int for the index and int for the version number is it not?
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    As Soaryn says, it is blittable and can most definitely be stored on an IComponentData or in NativeArrays or anywhere.
     
  4. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    Then, please explain why I get this error, as soon as I add a NativeArray<Entity> to an IComponentData.

    ArgumentException: Test contains a field of Unity.Collections.LowLevel.Unsafe.DisposeSentinel, which is neither primitive nor blittable.
    Unity.Entities.TypeManager.ThrowOnDisallowedComponentData (System.Type type, System.Type baseType, System.String baseTypeDesc) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1232)
    Unity.Entities.TypeManager.ThrowOnDisallowedComponentData (System.Type type, System.Type baseType, System.String baseTypeDesc) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1237)
    Unity.Entities.TypeManager.ThrowOnDisallowedComponentData (System.Type type, System.Type baseType, System.String baseTypeDesc) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1237)
    Unity.Entities.TypeManager.CheckIsAllowedAsComponentData (System.Type type, System.String baseTypeDesc) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1185)
    Unity.Entities.TypeManager.BuildComponentType (System.Type type, System.Int32[] writeGroups) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1279)
    Unity.Entities.TypeManager.BuildComponentType (System.Type type) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1250)
    Unity.Entities.TypeManager.AddAllComponentTypes (System.Type[] componentTypes, System.Int32 startTypeIndex, System.Collections.Generic.Dictionary`2[TKey,TValue] writeGroupByType) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1076)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.TypeManager:AddAllComponentTypes(Type[], Int32, Dictionary`2) (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1088)
    Unity.Entities.TypeManager:InitializeAllComponentTypes() (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:1038)
    Unity.Entities.TypeManager:Initialize() (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities/Types/TypeManager.cs:460)
    Unity.Entities.AttachToEntityClonerInjection:Initialize() (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities.Hybrid/Injection/CompanionGameObject.cs:27)
    Unity.Entities.AttachToEntityClonerInjection:.cctor() (at Library/PackageCache/com.unity.entities@0.7.0-preview.19/Unity.Entities.Hybrid/Injection/CompanionGameObject.cs:21)
    UnityEditor.EditorAssemblies:processInitializeOnLoadAttributes(Type[])
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    You can't add native containers to IComponentData as NativeArray is not blittable
    Nothing to do with Entity adding to IComponentData

    Use DynamicBuffer instead
     
  6. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    OK, thanks!