GetSingletonRW<T>()
Gets a reference to the singleton component, for read/write access.
Read time 1 minuteLast updated 3 days ago
Definition
- Type: Method
- Namespace: Unity.Entities
- Assembly: UnityEngine.EntitiesModule
public static RefRW<T> GetSingletonRW<T>() where T : unmanaged, IComponentData
Returns
Type | Description |
|---|---|
| RefRW<T> | The component. |
Remarks
NOTE: this 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.
This method differs from SystemAPI.GetSingleton in the following ways:
The query that it generates requests read/write access to , which registers the system as a writer of that component, so systems that read that component and update later wait for this system's jobs. SystemAPI.GetSingleton generates a read-only query, which registers the system as a reader instead.
TIt throws an exception if a job that reads or writes is still running, whereas SystemAPI.GetSingleton throws only if a job that writes is still running. Neither method completes the conflicting job for you, and both run this check only if safety checks are enabled. To complete the job, call EntityManager.CompleteDependencyBeforeRW first, or restructure the data dependencies.
TTIt increments the change version of , even if you write the same value, so queries that filter on changes to that component match the singleton entity. SystemAPI.GetSingleton leaves the change version unchanged.
TNot working in Entities.ForEach, IJobEntity, and Utility methods
Additional Resources: ComponentSystemBase.GetSingleton, EntityQuery.GetSingleton, EntityQuery.GetSingletonRW