# GetSingletonRW<T>()

> Gets a reference to the singleton component, for read/write access.

## Definition

* **Type:** Method
* **Namespace:** [Unity.Entities](/engine/7000.0/script-reference/unity/entities.md)
* **Assembly:** UnityEngine.EntitiesModule

```csharp
public static RefRW<T> GetSingletonRW<T>() where T : unmanaged, IComponentData
```

### Returns

| Type                                                                  | Description    |
| --------------------------------------------------------------------- | -------------- |
| [RefRW\<T>](/engine/7000.0/script-reference/unity/entities/refrw1.md) | 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](/engine/7000.0/script-reference/unity/entities/systemapi/getsingleton.md) in the following ways:

The query that it generates requests read/write access to `T`, 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](/engine/7000.0/script-reference/unity/entities/systemapi/getsingleton.md) generates a read-only query, which registers the system as a reader instead.

It throws an exception if a job that reads or writes `T` is still running, whereas [SystemAPI.GetSingleton](/engine/7000.0/script-reference/unity/entities/systemapi/getsingleton.md) throws only if a job that writes `T` 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](/engine/7000.0/script-reference/unity/entities/entitymanager/completedependencybeforerw.md) first, or restructure the data dependencies.

It increments the change version of `T`, even if you write the same value, so queries that filter on changes to that component match the singleton entity. [SystemAPI.GetSingleton](/engine/7000.0/script-reference/unity/entities/systemapi/getsingleton.md) leaves the change version unchanged.

Not working in Entities.ForEach, IJobEntity, and Utility methods

Additional Resources: [ComponentSystemBase.GetSingleton](/engine/7000.0/script-reference/unity/entities/componentsystembase/getsingleton.md), [EntityQuery.GetSingleton](/engine/7000.0/script-reference/unity/entities/entityquery/getsingleton.md), [EntityQuery.GetSingletonRW](/engine/7000.0/script-reference/unity/entities/entityquery/getsingletonrw.md)
