Version: Unity 7.0 Alpha (7000.0)
LanguageEnglish
  • C#

SystemAPI.HasSingleton

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public static bool HasSingleton();

Returns

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

Description

Checks whether a singleton component of the specified type exists.

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 SystemAPI.GetSingleton throws an exception.

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

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