Documentation

Unity Engine


Unity Engine


GetOrCreateSystemManaged

Retrieve the instance of a system of type T from the current World. If the system does not exist in this World, it will first be created.
Read time 3 minutesLast updated a day ago

Definition

  • Type: Method
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule

GetOrCreateSystemManaged<T>()

Retrieve the instance of a system of type
T
from the current World. If the system does not exist in this World, it will first be created.
public T GetOrCreateSystemManaged<T>() where T : ComponentSystemBase

Returns

Type

Description

TThe instance of system type
T
in this World. If the system does not exist in this World, it will first be created.

Remarks

Important: This function creates a sync point if a system is created, which means that the EntityManager waits for all currently running Jobs to complete before creating the system, and no additional Jobs can start before the function is finished. A sync point can cause a drop in performance because the ECS framework may not be able to make use of the processing power of all available cores.
Note: This system reference is not guaranteed to be safe to use. If the system or world is destroyed then the OnDestroy and cleanup functionality will have been called for this system.
If possible, using World.GetOrCreateSystem is preferred, and instead of public member data, component data is recommended for system level data that needs to be shared between systems or externally to them. This defines a data protocol for the system which is separated from the system functionality.
Private member data which is only used internally to the system is recommended.
Keep in mind using a managed reference for systems
  • encourages coupling of data and functionality
  • couples data to the system type with no direct path to decouple
  • does not provide lifetime or thread safety guarantees for data access
  • does not provide lifetime or thread safety guarantees for system access through the returned managed reference

GetOrCreateSystemManaged(Type)

Retrieve the instance of a system of type
type
from the current World. If the system does not exist in this World, it will first be created.
public ComponentSystemBase GetOrCreateSystemManaged(Type type)

Parameters

type

The system type

Returns

Type

Description

ComponentSystemBaseThe instance of system type
type
in this World. If the system does not exist in this World, it will first be created.

Remarks

Important: This function creates a sync point if a system is created, which means that the EntityManager waits for all currently running Jobs to complete before creating the system, and no additional Jobs can start before the function is finished. A sync point can cause a drop in performance because the ECS framework may not be able to make use of the processing power of all available cores.
Note: This system reference is not guaranteed to be safe to use. If the system or world is destroyed then the OnDestroy and cleanup functionality will have been called for this system.
If possible, using World.GetOrCreateSystem is preferred, and instead of public member data, component data is recommended for system level data that needs to be shared between systems or externally to them. This defines a data protocol for the system which is separated from the system functionality.
Private member data which is only used internally to the system is recommended.
Keep in mind using a managed reference for systems
  • encourages coupling of data and functionality
  • couples data to the system type with no direct path to decouple
  • does not provide lifetime or thread safety guarantees for data access
  • does not provide lifetime or thread safety guarantees for system access through the returned managed reference

GetOrCreateSystemManaged(SystemTypeIndex)

Retrieve the instance of a system of type
type
from the current World. If the system does not exist in this World, it will first be created.
public ComponentSystemBase GetOrCreateSystemManaged(SystemTypeIndex type)

Parameters

The system type

Returns

Type

Description

ComponentSystemBaseThe instance of system type
type
in this World. If the system does not exist in this World, it will first be created.