Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

EntityQuery.SetSingleton

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public void SetSingleton(T value);

Parameters

Parameter Description
value An instance of type T containing the values to set.

Description

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.

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 SetSingleton() function:



You can set and get the singleton value from a system: see ComponentSystemBase.SetSingleton and ComponentSystemBase.GetSingleton.

Additional resources: EntityQuery.GetSingleton, EntityQuery.GetSingletonEntity