docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method HasSingleton

    HasSingleton<T>()

    Checks whether a singleton component of the specified type exists.

    Declaration
    public static bool HasSingleton<T>() where T : unmanaged
    Returns
    Type Description
    bool

    True, if a singleton of the specified type exists in the current World.

    Type Parameters
    Name Description
    T

    The IComponentData subtype of the singleton component. This component type must not implement IEnableableComponent

    Remarks

    The SystemAPI singleton methods build their query with the default EntityQueryOptions flags, which exclude entities that have the Disabled component and entities that have the Prefab component. So if the only entity that has component T is disabled or is an entity prefab, this method returns false, and GetSingleton<T>() throws an exception.

    To find a singleton component on a disabled entity or on an entity prefab, create an EntityQuery with the IncludeDisabledEntities or IncludePrefab option, then call HasSingleton<T>() on that query.

    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if T implements IEnableableComponent and if safety checks are enabled.

    InvalidOperationException

    Thrown if more than one entity has component T and if safety checks are enabled.

    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)