Method SetSingleton
SetSingleton<T>(EntityQuery, T)
Sets the value of a singleton component.
Declaration
public static void SetSingleton<T>(this EntityQuery query, T value) where T : class
Parameters
Type | Name | Description |
---|---|---|
Entity |
query | The query |
T | value | An instance of type T containing the values to set. |
Type Parameters
Name | Description |
---|---|
T | The component type. This type must not implement IEnableable |
Remarks
For a component to be a singleton, there can be only one instance of that component that satisfies this query.
Note: singletons are otherwise normal entities. The EntityQuery and Component
To create a singleton, create an entity with the singleton component.
For example, if you had a component defined as:
public struct Singlet : IComponentData
{
public int Value;
}
You could create a singleton as follows:
Entity singletonEntity = entityManager.CreateEntity(typeof(Singlet));
entityManager.SetComponentData(singletonEntity, new Singlet { Value = 1 });
To update the singleton component after creation, you can use an EntityQuery object that
selects the singleton entity and call this SetSingleton()
function:
queryForSingleton.SetSingleton<Singlet>(new Singlet {Value = 1});
You can set and get the singleton value from a system: see Set
Exceptions
Type | Condition |
---|---|
Invalid |
Thrown if more than one instance of this component type exists in the world or the component type appears in more than one archetype. |