Class Level
The scene manager that contains the loaded scenes collection and spawns/deleted actors.
Inheritance
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public static class Level : Object
Properties
IsAnyActionPending
Checks if any scene action is pending
Declaration
[Unmanaged]
public static bool IsAnyActionPending { get; }
Property Value
|
System.Boolean
|
IsAnyActorInGame
Checks if any scene has any actor
Declaration
[Unmanaged]
public static bool IsAnyActorInGame { get; }
Property Value
|
System.Boolean
|
IsAnySceneLoaded
Checks if any scene has been loaded. Loaded scene means deserialized and added to the scenes collection.
Declaration
[Unmanaged]
public static bool IsAnySceneLoaded { get; }
Property Value
|
System.Boolean
|
LastSceneLoadTime
Gets the last scene load time (in UTC).
Declaration
[Unmanaged]
public static DateTime LastSceneLoadTime { get; }
Property Value
|
System.DateTime
|
Scenes
The loaded scenes collection.
Declaration
[Unmanaged]
public static Scene[] Scenes { get; }
Property Value
|
Scene[]
|
ScenesCount
Gets the scenes count.
Declaration
[Unmanaged]
public static int ScenesCount { get; }
Property Value
|
System.Int32
|
StreamingFrameBudget
Fraction of the frame budget to limit time spent on levels streaming. For example, value of 0.3 means that 30% of frame time can be spent on levels loading within a single frame (eg. 0.3 at 60fps is 4.8ms budget).
Declaration
[DebugCommand]
[Unmanaged]
public static float StreamingFrameBudget { get; set; }
Property Value
|
System.Single
|
TickEnabled
True if game objects (actors and scripts) can receive a tick during engine Update/LateUpdate/FixedUpdate events. Can be used to temporarily disable gameplay logic updating.
Declaration
[DebugCommand]
[Unmanaged]
public static bool TickEnabled { get; set; }
Property Value
|
System.Boolean
|
Methods
ChangeSceneAsync(SceneReference)
Unloads all active scenes and loads the given scene (in the background).
Declaration
public static bool ChangeSceneAsync(SceneReference sceneAsset)
Parameters
|
SceneReference
sceneAsset
The asset with the scene to load. |
Returns
|
System.Boolean
True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. |
ChangeSceneAsync(Guid)
Unloads all active scenes and loads the given scene (in the background).
Declaration
public static bool ChangeSceneAsync(Guid sceneAssetId)
Parameters
|
System.Guid
sceneAssetId
The scene asset identifier (scene to load). |
Returns
|
System.Boolean
True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. |
FindActor(Tag, Boolean, Actor)
Tries to find the actor with the given tag (returns the first one found).
Declaration
[Unmanaged]
public static Actor FindActor(Tag tag, bool activeOnly = false, Actor root = null)
Parameters
|
Tag
tag
The tag of the actor to search for. |
|
System.Boolean
activeOnly
Finds only an active actor. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Actor
Found actor or null. |
FindActor(Guid)
Tries to find actor with the given ID. It's very fast O(1) lookup.
Declaration
[Unmanaged]
public static Actor FindActor(Guid id)
Parameters
|
System.Guid
id
The id. |
Returns
|
Actor
Found actor or null. |
FindActor(String)
Tries to find the actor with the given name.
Declaration
[Unmanaged]
public static Actor FindActor(string name)
Parameters
|
System.String
name
The name of the actor. |
Returns
|
Actor
Found actor or null. |
FindActor(Type, Tag, Boolean, Actor)
Tries to find the actor of the given type and tag in all the loaded scenes.
Declaration
[Unmanaged]
public static Actor FindActor([TypeReference] Type type, Tag tag, bool activeOnly = false, Actor root = null)
Parameters
|
System.Type
type
Type of the actor to search for. Includes any actors derived from the type. Supports interface types. |
|
Tag
tag
The tag of the actor to search for. |
|
System.Boolean
activeOnly
Finds only an active actor. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Actor
Actor instance if found, null otherwise. |
FindActor(Type, Boolean)
Tries to find the actor of the given type in all the loaded scenes.
Declaration
[Unmanaged]
public static Actor FindActor([TypeReference] Type type, bool activeOnly = false)
Parameters
|
System.Type
type
Type of the actor to search for. Includes any actors derived from the type. Supports interface types. |
|
System.Boolean
activeOnly
Finds only an active actor. |
Returns
|
Actor
Found actor or null. |
FindActor(Type, String)
Tries to find the actor of the given type and name in all the loaded scenes.
Declaration
[Unmanaged]
public static Actor FindActor([TypeReference] Type type, string name)
Parameters
|
System.Type
type
Type of the actor to search for. Includes any actors derived from the type. Supports interface types. |
|
System.String
name
The name of the actor. |
Returns
|
Actor
Actor instance if found, null otherwise. |
FindActor<T>()
Tries to find actor of the given type in all loaded scenes.
Declaration
public static T FindActor<T>()
where T : Actor
Returns
|
T
Found actor or null. |
Type Parameters
|
T
Type of the object. |
FindActor<T>(Tag, Actor)
Tries to find actor of the given type and tag in a root actor or all loaded scenes.
Declaration
public static T FindActor<T>(Tag tag, Actor root = null)
where T : Actor
Parameters
|
Tag
tag
A tag on the object. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
T
Found actor or null. |
Type Parameters
|
T
Type of the object. |
FindActor<T>(ref Guid)
Tries to find actor with the given ID in all loaded scenes. It's very fast O(1) lookup.
Declaration
public static T FindActor<T>(ref Guid id)
where T : Actor
Parameters
|
System.Guid
id
The id. |
Returns
|
T
Found actor or null. |
Type Parameters
|
T
Type of the object. |
FindActor<T>(String)
Tries to find actor of the given type and name in all loaded scenes.
Declaration
public static T FindActor<T>(string name)
where T : Actor
Parameters
|
System.String
name
Name of the object. |
Returns
|
T
Found actor or null. |
Type Parameters
|
T
Type of the object. |
FindActors(Tag, Boolean, Actor)
Tries to find the actors with the given tag (returns all found).
Declaration
[Unmanaged]
public static Actor[] FindActors(Tag tag, bool activeOnly = false, Actor root = null)
Parameters
|
Tag
tag
The tag of the actor to search for. |
|
System.Boolean
activeOnly
Find only active actors. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Actor[]
Found actors or empty if none. |
FindActorsByParentTag(Tag, Boolean, Actor)
Search actors using a parent parentTag.
Declaration
[Unmanaged]
public static Actor[] FindActorsByParentTag(Tag parentTag, bool activeOnly = false, Actor root = null)
Parameters
|
Tag
parentTag
The tag to search actors with subtags belonging to this tag |
|
System.Boolean
activeOnly
Find only active actors. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Actor[]
Returns all actors that have subtags belonging to the given parent parentTag |
FindScene(Guid)
Tries to find scene with given ID.
Declaration
[Unmanaged]
public static Scene FindScene(Guid id)
Parameters
|
System.Guid
id
Scene id. |
Returns
|
Scene
Found scene or null. |
FindScript(Type)
Tries to find the script of the given type in all the loaded scenes.
Declaration
[Unmanaged]
public static Script FindScript([TypeReference] Type type)
Parameters
|
System.Type
type
Type of the script to search for. Includes any scripts derived from the type. Supports interface types. |
Returns
|
Script
Found script or null. |
FindScript<T>()
Tries to find script of the given type in all loaded scenes.
Declaration
public static T FindScript<T>()
where T : Script
Returns
|
T
Found script or null. |
Type Parameters
|
T
Type of the object. |
GetActors(Type, Boolean)
Finds all the actors of the given type in all the loaded scenes.
Declaration
[Unmanaged]
public static Actor[] GetActors([TypeReference] Type type, bool activeOnly = false)
Parameters
|
System.Type
type
Type of the actor to search for. Includes any actors derived from the type. |
|
System.Boolean
activeOnly
Finds only active actors in the scene. |
Returns
|
Actor[]
Found actors list. |
GetActors<T>(Boolean)
Finds all the actors of the given type in all the loaded scenes.
Declaration
public static T[] GetActors<T>(bool activeOnly = false)
where T : Actor
Parameters
|
System.Boolean
activeOnly
Finds only active actors. |
Returns
|
T[]
Found actors list. |
Type Parameters
|
T
Type of the object. |
GetLayerIndex(String)
Gets the zero-based index of the layer.
Declaration
[Unmanaged]
public static int GetLayerIndex(string layer)
Parameters
|
System.String
layer
|
Returns
|
System.Int32
|
GetLayerName(Int32)
Gets the name of the layer based on the index.
Declaration
[Unmanaged]
public static string GetLayerName(int layerIndex)
Parameters
|
System.Int32
layerIndex
The index to find the layer string. 0 - 32. |
Returns
|
System.String
The layer string. Returns a blank string if index not found. |
GetScene(Int32)
Gets the scene.
Declaration
[Unmanaged]
public static Scene GetScene(int index)
Parameters
|
System.Int32
index
The index. |
Returns
|
Scene
The scene object (loaded). |
GetScripts(Type, Actor)
Finds all the scripts of the given type in an actor or all the loaded scenes.
Declaration
[Unmanaged]
public static Script[] GetScripts([TypeReference] Type type, Actor root = null)
Parameters
|
System.Type
type
Type of the script to search for. Includes any scripts derived from the type. |
|
Actor
root
The root to find scripts. If null, will search in all scenes. |
Returns
|
Script[]
Found scripts list. |
GetScripts<T>(Actor)
Finds all the scripts of the given type in an actor or all the loaded scenes.
Declaration
public static T[] GetScripts<T>(Actor root = null)
where T : Script
Parameters
|
Actor
root
The root to find scripts. If null, will search in all scenes |
Returns
|
T[]
Found scripts list. |
Type Parameters
|
T
Type of the object. |
LoadScene(SceneReference)
Loads scene from the asset.
Declaration
public static bool LoadScene(SceneReference sceneAsset)
Parameters
|
SceneReference
sceneAsset
The asset with the scene to load. |
Returns
|
System.Boolean
True if action fails (given asset is not a scene asset, missing data, scene loading error), otherwise false. |
LoadScene(Guid)
Loads scene from the asset.
Declaration
[Unmanaged]
public static bool LoadScene(Guid id)
Parameters
|
System.Guid
id
Scene ID |
Returns
|
System.Boolean
True if loading cannot be done, otherwise false. |
LoadSceneAsync(SceneReference)
Loads scene from the asset. Done in the background.
Declaration
public static bool LoadSceneAsync(SceneReference sceneAsset)
Parameters
|
SceneReference
sceneAsset
The asset with the scene to load. |
Returns
|
System.Boolean
True if failed (given asset is not a scene asset, missing data), otherwise false. |
LoadSceneAsync(Guid)
Loads scene from the asset. Done in the background.
Declaration
[Unmanaged]
public static bool LoadSceneAsync(Guid id)
Parameters
|
System.Guid
id
Scene ID |
Returns
|
System.Boolean
True if loading cannot be done, otherwise false. |
LoadSceneFromBytes(Byte[])
Loads scene from the bytes.
Declaration
[Unmanaged]
public static Scene LoadSceneFromBytes(byte[] data)
Parameters
|
System.Byte[]
data
The scene data to load. |
Returns
|
Scene
Loaded scene object, otherwise null if cannot load data (then see log for more information). |
PreloadSceneAsync(SceneReference)
Begins preloading scene in the background. Intended to use by scene streaming systems that want to prepare scene but not add to the level yet. Loads scene asset, deserializes actors and scripts, setup objects hierarchy with transformations and initializes them (incl. calling OnAwake for scripts). Preloaded scene is not added to the loaded scenes and not active in the game (no BeginPlay/OnEnable/OnStart called yet). Use LoadScene(Guid) or LoadSceneAsync(Guid) to finish loading preloaded scene and add it to the level. Preloaded scene can be normally unloaded via UnloadScene(Guid) to release resources if it's not needed anymore.
Declaration
public static bool PreloadSceneAsync(SceneReference sceneAsset)
Parameters
|
SceneReference
sceneAsset
The asset with the scene to preload. |
Returns
|
System.Boolean
True if preloading cannot be done, otherwise false. |
PreloadSceneAsync(Guid)
Begins preloading scene in the background. Intended to use by scene streaming systems that want to prepare scene but not add to the level yet. Loads scene asset, deserializes actors and scripts, setup objects hierarchy with transformations and initializes them (incl. calling OnAwake for scripts). Preloaded scene is not added to the loaded scenes and not active in the game (no BeginPlay/OnEnable/OnStart called yet). Use LoadScene(Guid) or LoadSceneAsync(Guid) to finish loading preloaded scene and add it to the level. Preloaded scene can be normally unloaded via UnloadScene(Guid) to release resources if it's not needed anymore.
Declaration
[Unmanaged]
public static bool PreloadSceneAsync(Guid id)
Parameters
|
System.Guid
id
Scene ID |
Returns
|
System.Boolean
True if preloading cannot be done, otherwise false. |
SaveAllScenes()
Saves all scenes to the assets.
Declaration
[Unmanaged]
public static bool SaveAllScenes()
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
SaveAllScenesAsync()
Saves all scenes to the assets. Done in the background.
Declaration
[Unmanaged]
public static void SaveAllScenesAsync()
SaveScene(Scene, Boolean)
Saves scene to the asset.
Declaration
[Unmanaged]
public static bool SaveScene(Scene scene, bool prettyJson = true)
Parameters
|
Scene
scene
Scene to serialize. |
|
System.Boolean
prettyJson
True if use pretty Json format writer, otherwise will use the compact Json format writer that packs data to use less memory and perform the action faster. |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
SaveSceneAsync(Scene)
Saves scene to the asset. Done in the background.
Declaration
[Unmanaged]
public static void SaveSceneAsync(Scene scene)
Parameters
|
Scene
scene
Scene to serialize. |
SaveSceneToBytes(Scene, Boolean)
Saves scene to the bytes.
Declaration
[Unmanaged]
public static byte[] SaveSceneToBytes(Scene scene, bool prettyJson = true)
Parameters
|
Scene
scene
Scene to serialize. |
|
System.Boolean
prettyJson
True if use pretty Json format writer, otherwise will use the compact Json format writer that packs data to use less memory and perform the action faster. |
Returns
|
System.Byte[]
The result data or empty if failed. |
SpawnActor(Actor)
Spawn actor on the scene
Declaration
[Unmanaged]
public static bool SpawnActor(Actor actor)
Parameters
|
Actor
actor
Actor to spawn |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
SpawnActor(Actor, Actor)
Spawns actor on the scene.
Declaration
[Unmanaged]
public static bool SpawnActor(Actor actor, Actor parent)
Parameters
|
Actor
actor
The actor to spawn. |
|
Actor
parent
The parent actor (will link spawned actor with this parent). |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
UnloadAllScenes()
Unloads all scenes. Cancels all scene preloading.
Declaration
[Unmanaged]
public static bool UnloadAllScenes()
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
UnloadAllScenesAsync()
Unloads all scenes. Done in the background. Cancels all scene preloading.
Declaration
[Unmanaged]
public static void UnloadAllScenesAsync()
UnloadScene(Scene)
Unloads given scene.
Declaration
[Unmanaged]
public static bool UnloadScene(Scene scene)
Parameters
|
Scene
scene
Scene |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
UnloadScene(SceneReference)
Unloads given scene.
Declaration
public static bool UnloadScene(SceneReference sceneAsset)
Parameters
|
SceneReference
sceneAsset
The asset with the scene to unload. |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
UnloadScene(Guid)
Unloads given scene.
Declaration
[Unmanaged]
public static bool UnloadScene(Guid id)
Parameters
|
System.Guid
id
Scene ID |
Returns
|
System.Boolean
True if action cannot be done, otherwise false. |
UnloadSceneAsync(Scene)
Unloads given scene. Done in the background.
Declaration
[Unmanaged]
public static void UnloadSceneAsync(Scene scene)
Parameters
|
Scene
scene
Scene |
Events
ActorActiveChanged
Occurs when actor active state gets modified.
Declaration
[Unmanaged]
public static event Action<Actor> ActorActiveChanged
Event Type
|
System.Action<Actor>
|
ActorDeleted
Occurs when actor is removed from the game.
Declaration
[Unmanaged]
public static event Action<Actor> ActorDeleted
Event Type
|
System.Action<Actor>
|
ActorNameChanged
Occurs when actor name gets changed.
Declaration
[Unmanaged]
public static event Action<Actor> ActorNameChanged
Event Type
|
System.Action<Actor>
|
ActorOrderInParentChanged
Occurs when actor index in parent actor children gets changed.
Declaration
[Unmanaged]
public static event Action<Actor> ActorOrderInParentChanged
Event Type
|
System.Action<Actor>
|
ActorParentChanged
Occurs when actor parent gets changed. Arguments: actor and previous parent actor.
Declaration
[Unmanaged]
public static event Action<Actor, Actor> ActorParentChanged
Event Type
|
System.Action<Actor, Actor>
|
ActorSpawned
Occurs when new actor gets spawned to the game.
Declaration
[Unmanaged]
public static event Action<Actor> ActorSpawned
Event Type
|
System.Action<Actor>
|
SceneLoaded
Fired when scene gets loaded.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneLoaded
Event Type
|
System.Action<Scene, System.Guid>
|
SceneLoadError
Fired when scene cannot be loaded (argument is error number).
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneLoadError
Event Type
|
System.Action<Scene, System.Guid>
|
SceneLoading
Fired when scene starts loading.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneLoading
Event Type
|
System.Action<Scene, System.Guid>
|
ScenePreloaded
Fired when scene gets preloaded (loaded but not yet added to the level).
Declaration
[Unmanaged]
public static event Action<Scene, Guid> ScenePreloaded
Event Type
|
System.Action<Scene, System.Guid>
|
SceneSaved
Fired when scene gets saved.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneSaved
Event Type
|
System.Action<Scene, System.Guid>
|
SceneSaveError
Fired when scene gets saving error.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneSaveError
Event Type
|
System.Action<Scene, System.Guid>
|
SceneSaving
Fired when scene starts saving.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneSaving
Event Type
|
System.Action<Scene, System.Guid>
|
SceneUnloaded
Fired when scene gets unloaded.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneUnloaded
Event Type
|
System.Action<Scene, System.Guid>
|
SceneUnloading
Fired when scene gets unloading.
Declaration
[Unmanaged]
public static event Action<Scene, Guid> SceneUnloading
Event Type
|
System.Action<Scene, System.Guid>
|
ScriptsReload
Fired when scene reloads scripts (scenes serialized and unloaded). All user objects should be cleaned up.
Declaration
[Unmanaged]
public static event Action ScriptsReload
Event Type
|
System.Action
|
ScriptsReloaded
Fired when scene reloaded scripts (new scripting is loaded). All user objects can be restored before scenes reloading.
Declaration
[Unmanaged]
public static event Action ScriptsReloaded
Event Type
|
System.Action
|
ScriptsReloadEnd
Fired when scene ends reloading scripts.
Declaration
[Unmanaged]
public static event Action ScriptsReloadEnd
Event Type
|
System.Action
|
ScriptsReloadStart
Fired when scene starts reloading scripts.
Declaration
[Unmanaged]
public static event Action ScriptsReloadStart
Event Type
|
System.Action
|