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

EntityQuery.GetSingletonRW

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 RefRW<T> GetSingletonRW();

Returns

RefRW<T> A reference to the singleton component.

Description

Gets a reference to a singleton component, for read/write access. Note that if querying a singleton component from a system-associated entity, the query must include either EntityQueryOptions.IncludeSystems or the SystemInstance component.

A singleton component is a component of which only one instance exists that satisfies this query.

The reference refers directly to the singleton's component memory. Structural changes to the chunk where the singleton resides can invalidate this reference and result in crashes or undefined behaviour if the reference is used after structural changes.

If safety checks are enabled, this method throws an exception if a job that reads or writes T is still running, whereas EntityQuery.GetSingleton throws only if a job that writes T is still running. Neither method completes the conflicting job for you. This method also increments the change version of T, even if you don't write to the returned reference, so queries that filter on changes to T match the singleton entity.

Additional resources: EntityQuery.GetSingleton, EntityQuery.SetSingleton, EntityQuery.GetSingletonEntity, EntityQuery.GetSingletonBuffer, ComponentSystemBase.GetSingleton