docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method GetSingletonRW

    GetSingletonRW<T>()

    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.

    Declaration
    [GenerateTestsForBurstCompatibility(GenericTypeArguments = new Type[] { typeof(BurstCompatibleComponentData) })]
    public RefRW<T> GetSingletonRW<T>() where T : unmanaged, IComponentData
    Returns
    Type Description
    RefRW<T>

    A reference to the singleton component.

    Type Parameters
    Name Description
    T

    The component type.

    Remarks

    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 GetSingleton<T>() 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.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the number of entities that match this query is not exactly one.

    InvalidOperationException

    Thrown if this query doesn't have read-write access to T, if T is a zero-sized component, or if T implements IEnableableComponent, and if safety checks are enabled.

    See Also
    GetSingleton<T>()
    SetSingleton<T>(T)
    GetSingletonEntity()
    GetSingletonBuffer<T>(bool)
    GetSingleton<T>()
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)