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

ComponentGroup - GetComponentArray

Discussion in 'Entity Component System' started by jamiebrynes, May 4, 2018.

  1. jamiebrynes

    jamiebrynes

    Joined:
    Sep 12, 2017
    Posts:
    18
    I've got a question about the API on the ComponentGroup struct.. there doesn't appear to be any GetComponentArray method (components attached to a GameObject), but there are methods for IComponentData and ISharedComponentData.

    Is there a technical reason that this wasn't included?
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    I don't know what component group you are looking for...

    But there are all methods to get ComponentArrays, ComponentDataArrays and so on!

    Metadata of ComponentGroup:
    Code (CSharp):
    1.     public class ComponentGroup : IDisposable {
    2.         public ComponentType[] Types { get; }
    3.         public bool IsEmptyIgnoreFilter { get; }
    4.  
    5.         public void AddDependency(JobHandle job);
    6.         public int CalculateLength();
    7.         public bool CompareComponents(ComponentType[] componentTypes);
    8.         public void CompleteDependency();
    9.         public ForEachComponentGroupFilter CreateForEachFilter<SharedComponent1>(List<SharedComponent1> sharedComponent1) where SharedComponent1 : struct, ISharedComponentData;
    10.         public void Dispose();
    11.         public int GetCombinedComponentOrderVersion();
    12.         public ComponentDataArray<T> GetComponentDataArray<T>(ForEachComponentGroupFilter filter, int filterIdx) where T : struct, IComponentData;
    13.         public ComponentDataArray<T> GetComponentDataArray<T>() where T : struct, IComponentData;
    14.         public JobHandle GetDependency();
    15.         public EntityArray GetEntityArray();
    16.         public FixedArrayArray<T> GetFixedArrayArray<T>() where T : struct;
    17.         public SharedComponentDataArray<T> GetSharedComponentDataArray<T>() where T : struct, ISharedComponentData;
    18.         public void ResetFilter();
    19.         public void SetFilter<SharedComponent1>(SharedComponent1 sharedComponent1) where SharedComponent1 : struct, ISharedComponentData;
    20.     }
    21. }
    MetaData of ComponentGroupExtensionsForComponentArray
    Code (CSharp):
    1.    public static class ComponentGroupExtensionsForComponentArray {
    2.         public static ComponentArray<T> GetComponentArray<T>(this ComponentGroup group) where T : Component;
    3.     }
     
  3. jamiebrynes

    jamiebrynes

    Joined:
    Sep 12, 2017
    Posts:
    18
    Those pesky extension functions! Thanks :)