Documentation

Unity Engine


Unity Engine


ImportEntity

Optional main-world entity to copy into the per-section streaming world before ProcessAfterLoadGroup runs.
Read time 2 minutesLast updated 2 days ago

Definition

  • Type: Field
  • Namespace: Unity.Entities
  • Assembly: UnityEngine.EntitiesModule
public Entity ImportEntity

Remarks

Use this to deliver per-instance runtime data to ProcessAfterLoad systems. Build a data entity in the main world carrying whatever components your ProcessAfterLoad system needs to read, then set RequestSceneLoaded.ImportEntity on the scene meta entity (typically via ImportEntity at load time). The streaming system copies that entity and all of its components into the section's loading world; ProcessAfterLoad systems then query for the imported components as if they were native to the streaming world.
The imported entity follows the same lifetime rules as any other entity in the streaming world: your
ProcessAfterLoad
system may consume and destroy it, and any imported entity that is still alive after ProcessAfterLoadGroup runs is tagged with SceneTag and moved into the main world together with the rest of the section's entities. Destroy it inside your
ProcessAfterLoad
system if you only want it to live for the duration of the load.
You own the source entity in the main world; the streaming system only reads from it. Destroy the source entity yourself when it is no longer needed, but keep it alive until the scene load completes. RequestSceneLoaded.ImportEntity may be Entity.Null, in which case no import is performed. A non-null reference to an entity that does not exist (because it was never created, or because it was destroyed before the scene finished loading) is treated as a programming error: the import is skipped and an error is logged.
Because RequestSceneLoaded is automatically propagated from the scene meta entity to its sections, setting RequestSceneLoaded.ImportEntity on the scene meta entity causes that entity to be imported into every section's streaming world. Override the per-section value by writing RequestSceneLoaded on the individual section meta entity if you need different (or no) import data for specific sections.