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

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 :)