how to get an singleton entity from a monobehavior?

hey, i try to acess an IComponent thingy from a MonoBehavior to set some options for my entities.

it works in my system on the OnUpdate with:

LivingControllerData lcd = SystemAPI.GetSingleton<LivingControllerData>();

now i want to put there some settings that the system can then use.

so i wanted to acces this one entity (its LivingControlData) in a monobehavior to set stuff on key presses.

i did it with the following in the update method of the monobehavior.

EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
LivingControllerData lcd = entityManager.UniversalQuery.GetSingleton<LivingControllerData>();

but it throws:
InvalidOperationException: GetSingleton() requires that exactly one entity exists that matches this query, but there are 14.

but no, there are not 14 entities with a “LivingControllerData” IComponentData, there is only one (it was created in the baker).


there is only one, not 14.

what am i doing wrong here?
is this the wrong approach in general to access that entity (its component) from a monobehavior?

im using:
using 1.0.0-pre.15

you can create an EntityQuery, and get the Singleton (or the singleton entity) from that Query:

EntityManager _entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
EntityQuery colorTablesQ = _entityManager.CreateEntityQuery(new ComponentType[] { typeof(ColorTables) });
colorTablesQ.TryGetSingletonEntity<ColorTables>(out Entity colorTablesEntity)
5 Likes

ty, that was then not so complicated at all.