Is it possible to list the entities I need with components via ForEachLambdaJobDescription
Entities without the SystemBase
class?
Let’s say there is some event that enumerates entities only once in a lifetime, and calling onUpdate
SystemBase
every time sounds somehow too cumbersome.
Yes. You can query and grab whatever data you need, even from a common MonoBehaviour
.
But be aware that everything Unity.Collections
( NativeArray<T>
etc) will be slow to read/write outside a job. So still prefer jobs where possible (you can start them from Monobehaviour
s too)
void Start ()
{
var world = World.DefaultGameObjectInjectionWorld;
var entityManager = world.EntityManager;
var query = entityManager.CreateEntityQuery(
typeof(RenderBounds)
);
NativeArray<Entity> entities = query.ToEntityArray( Allocator.Temp );
Entity[] entitiesArray = entities.ToArray();
NativeArray<Entity> renderBounds = query.ToComponentDataArray<RenderBounds>( Allocator.Temp );
RenderBounds[] renderBoundsArray = renderBounds.ToArray();
}