Search Unity

Test if native collection is allocated

Discussion in 'Entity Component System' started by xVergilx, Feb 1, 2019.

  1. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Title. Is there a way to check if some native collection has been allocated or not?
    Haven't found anything on a topic.
     
    DragonCoder likes this.
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    IsCreated property
     
    xVergilx likes this.
  3. Joouur

    Joouur

    Joined:
    Feb 18, 2016
    Posts:
    10
    Wouldn't that property just be for if the object is not null? What about if the objects within a native collection have not been initialized? (Sorry if it sounds dumb, I have never used that property before)

    Like for example

    NativeArray<SomeStruct> someStructs = new NativeArray<SomeStruct>(length, Allocator.Temp, NativeArrayOptions.UninitializedMemory);


    Is it possible to check all obejcts in the array if they have been initialized within the memory? or it has to be done one-by-one?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    If you initialize native collection, IsCreated say true, if you just declare it's say false.
    Also all native collections is structs, it's value type. Struct cannot be null, and a struct variable cannot be assigned null unless the variable is declared as a nullable type.
     
    Joouur and xVergilx like this.