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 |
| InvalidOperationException | Thrown if more than one entity has component
|