diff --git a/src/ComponentDepot.cs b/src/ComponentDepot.cs index c6eca73..c9c84f1 100644 --- a/src/ComponentDepot.cs +++ b/src/ComponentDepot.cs @@ -185,6 +185,11 @@ namespace MoonTools.ECS } } + public Entity FilterNthEntity(Filter filter, int index) + { + return new Entity(filterSignatureToEntityIDs[filter.Signature][index]); + } + public Entity FilterRandomEntity(Filter filter) { var randomIndex = RandomGenerator.Next(FilterCount(filter)); diff --git a/src/Filter.cs b/src/Filter.cs index bf7fefa..b229728 100644 --- a/src/Filter.cs +++ b/src/Filter.cs @@ -20,5 +20,8 @@ namespace MoonTools.ECS public int Count => ComponentDepot.FilterCount(this); public bool Empty => Count == 0; + + // WARNING: this WILL crash if the index is out of range! + public Entity NthEntity(int index) => ComponentDepot.FilterNthEntity(this, index); } }