SetSingleton<T>(T)
Sets the value of a singleton component. Note that if querying a singleton component from a system-associated entity, the query must include either EntityQueryOptions.IncludeSystems or the SystemInstance component.
Read time 1 minuteLast updated a day ago
Definition
- Type: Method
- Namespace: Unity.Entities
- Assembly: UnityEngine.EntitiesModule
public void SetSingleton<T>(T value) where T : unmanaged, IComponentData
Parameters
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 ComponentSystemBase singleton functions add checks that you have not created two instances of a type that can be accessed by this singleton query, but other APIs do not prevent such accidental creation.
To create a singleton, create an entity with the singleton component.
For example, if you had a component defined as:
You could create a singleton as follows:
To update the singleton component after creation, you can use an EntityQuery object that selects the singleton entity and call this function:
SetSingleton()You can set and get the singleton value from a system: see ComponentSystemBase.SetSingleton and ComponentSystemBase.GetSingleton.
Additional Resources: EntityQuery.GetSingleton, EntityQuery.GetSingletonEntity