文档

Unity Engine

Unity Engine

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.
阅读时间1 分钟最后更新于 19 天前

Definition

  • Type: Method
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule
public RefRW<T> GetSingletonRW<T>() where T : unmanaged, IComponentData

Returns

Type

Description

RefRW<T>A reference to the singleton component.

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 EntityQuery.GetSingleton 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.