Class Level
The scene manager that contains the loaded scenes collection and spawns/deleted actors.
Inheritance
Assembly: FlaxEngine.dll
File: Engine/Level/Level.h
Syntax
public class Level
Fields
ActorActiveChanged
Occurs when actor active state gets modified.
Declaration
public static Delegate<Actor* > ActorActiveChanged
Field Value
|
Delegate<Actor >
|
ActorDeleted
Occurs when actor is removed from the game.
Declaration
public static Delegate<Actor* > ActorDeleted
Field Value
|
Delegate<Actor >
|
ActorNameChanged
Occurs when actor name gets changed.
Declaration
public static Delegate<Actor* > ActorNameChanged
Field Value
|
Delegate<Actor >
|
ActorOrderInParentChanged
Occurs when actor index in parent actor children gets changed.
Declaration
public static Delegate<Actor* > ActorOrderInParentChanged
Field Value
|
Delegate<Actor >
|
ActorParentChanged
Occurs when actor parent gets changed. Arguments: actor and previous parent actor.
Declaration
public static Delegate<Actor* , Actor* > ActorParentChanged
Field Value
|
Delegate<Actor , Actor >
|
ActorSpawned
Occurs when new actor gets spawned to the game.
Declaration
public static Delegate<Actor* > ActorSpawned
Field Value
|
Delegate<Actor >
|
Layers
SceneLoaded
Fired when scene gets loaded.
Declaration
public static Delegate<Scene* , Guid> SceneLoaded
Field Value
|
Delegate<Scene , Guid>
|
SceneLoadError
Fired when scene cannot be loaded (argument is error number).
Declaration
public static Delegate<Scene* , Guid> SceneLoadError
Field Value
|
Delegate<Scene , Guid>
|
SceneLoading
Fired when scene starts loading.
Declaration
public static Delegate<Scene* , Guid> SceneLoading
Field Value
|
Delegate<Scene , Guid>
|
Scenes
The loaded scenes collection.
Declaration
public static Array<Scene* > Scenes
Field Value
|
Array<Scene >
|
SceneSaved
Fired when scene gets saved.
Declaration
public static Delegate<Scene* , Guid> SceneSaved
Field Value
|
Delegate<Scene , Guid>
|
SceneSaveError
Fired when scene gets saving error.
Declaration
public static Delegate<Scene* , Guid> SceneSaveError
Field Value
|
Delegate<Scene , Guid>
|
SceneSaving
Fired when scene starts saving.
Declaration
public static Delegate<Scene* , Guid> SceneSaving
Field Value
|
Delegate<Scene , Guid>
|
ScenesLock
The scenes collection lock.
Declaration
public static CriticalSection ScenesLock
Field Value
|
CriticalSection
|
SceneUnloaded
Fired when scene gets unloaded.
Declaration
public static Delegate<Scene* , Guid> SceneUnloaded
Field Value
|
Delegate<Scene , Guid>
|
SceneUnloading
Fired when scene gets unloading.
Declaration
public static Delegate<Scene* , Guid> SceneUnloading
Field Value
|
Delegate<Scene , Guid>
|
ScriptsReload
Fired when scene reloads scripts (scenes serialized and unloaded). All user objects should be cleaned up.
Declaration
public static Action ScriptsReload
Field Value
|
Action
|
ScriptsReloaded
Fired when scene reloaded scripts (new scripting is loaded). All user objects can be restored before scenes reloading.
Declaration
public static Action ScriptsReloaded
Field Value
|
Action
|
ScriptsReloadEnd
Fired when scene ends reloading scripts.
Declaration
public static Action ScriptsReloadEnd
Field Value
|
Action
|
ScriptsReloadStart
Fired when scene starts reloading scripts.
Declaration
public static Action ScriptsReloadStart
Field Value
|
Action
|
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
public static float StreamingFrameBudget
Field Value
|
float
|
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
public static bool TickEnabled
Field Value
|
bool
|
Methods
CallBeginPlay(Actor* obj)
Calls BeginPlay event for the given actor.
Use it for custom actors created from code but not added to the any scene. Otherwise there may be some internal state issues. Some actor types cache data on play mode begin so it's important to call this event for them.
Declaration
public static void CallBeginPlay(Actor* obj)
Parameters
|
Actor
obj
The actor to initialize. |
CollectPostFxVolumes(RenderContext& renderContext)
Collects all the post fx volumes.
Declaration
public static void CollectPostFxVolumes(RenderContext& renderContext)
Parameters
|
RenderContext
renderContext
The rendering context. |
ConstructParentActorsTreeList(const Array<Actor* >& input, Array<Actor* >& output)
Construct list with actors from input list that contains only parent actors (no children)
Declaration
public static void ConstructParentActorsTreeList(const Array<Actor* >& input, Array<Actor* >& output)
Parameters
|
Array<Actor >
input
Input array of actors |
|
Array<Actor >
output
Output array with only parents |
ConstructSolidActorsTreeList(const Array<Actor* >& input, Array<Actor* >& output)
Construct valid and solid list with actors from input list with whole tree for them (valid for fast serialization)
Declaration
public static void ConstructSolidActorsTreeList(const Array<Actor* >& input, Array<Actor* >& output)
Parameters
|
Array<Actor >
input
Input array of actors |
|
Array<Actor >
output
Output linear array of actors from up to down the tree with all children of given input actors |
DeleteActor(Actor* actor)
Deletes actor from the scene.
Declaration
public static bool DeleteActor(Actor* actor)
Parameters
|
Actor
actor
The actor to delete. |
Returns
|
bool
True if action cannot be done, otherwise false. |
DrawActors(RenderContextBatch& renderContextBatch, byte category = 0)
Draws all the actors.
Declaration
public static void DrawActors(RenderContextBatch& renderContextBatch, byte category = 0)
Parameters
|
RenderContextBatch
renderContextBatch
The rendering context batch. |
|
byte
category
The actors category to draw (see SceneRendering::DrawCategory). |
FindActor()
Tries to find the actor of the given type in all the loaded scenes.
Declaration
public static T* FindActor()
Returns
|
T
Actor instance if found, null otherwise. |
Type Parameters
|
typename T
|
FindActor(const Guid& id)
Tries to find actor with the given ID. It's very fast O(1) lookup.
Declaration
public static Actor* FindActor(const Guid& id)
Parameters
|
Guid
id
The id. |
Returns
|
Actor
Found actor or null. |
FindActor(const MClass* type, bool activeOnly=false)
Tries to find the actor of the given type in all the loaded scenes.
Declaration
public static Actor* FindActor(const MClass* type, bool activeOnly=false)
Parameters
|
MClass
type
Type of the actor to search for. Includes any actors derived from the type. Supports interface types. |
|
bool
activeOnly
Finds only an active actor. |
Returns
|
Actor
Found actor or null. |
FindActor(const MClass* type, const StringView& name)
Tries to find the actor of the given type and name in all the loaded scenes.
Declaration
public static Actor* FindActor(const MClass* type, const StringView& name)
Parameters
|
MClass
type
Type of the actor to search for. Includes any actors derived from the type. Supports interface types. |
|
StringView
name
The name of the actor. |
Returns
|
Actor
Actor instance if found, null otherwise. |
FindActor(const MClass* type, const Tag& tag, bool activeOnly=false, Actor* root=nullptr)
Tries to find the actor of the given type and tag in all the loaded scenes.
Declaration
public static Actor* FindActor(const MClass* type, const Tag& tag, bool activeOnly=false, Actor* root=nullptr)
Parameters
|
MClass
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. |
|
bool
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(const StringView& name)
Tries to find the actor with the given name.
Declaration
public static Actor* FindActor(const StringView& name)
Parameters
|
StringView
name
The name of the actor. |
Returns
|
Actor
Found actor or null. |
FindActor(const Tag& tag, Actor* root=nullptr)
Tries to find the actor of the given type and tag in a root actor or all the loaded scenes. The tag of the actor to search for. The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes.
Declaration
public static T* FindActor(const Tag& tag, Actor* root=nullptr)
Parameters
|
Tag
tag
|
|
Actor
root
|
Returns
|
T
Actor instance if found, null otherwise. |
Type Parameters
|
typename T
|
FindActor(const Tag& tag, bool activeOnly=false, Actor* root=nullptr)
Tries to find the actor with the given tag (returns the first one found).
Declaration
public static Actor* FindActor(const Tag& tag, bool activeOnly=false, Actor* root=nullptr)
Parameters
|
Tag
tag
The tag of the actor to search for. |
|
bool
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. |
FindActors(const Tag& tag, const bool activeOnly=false, Actor* root=nullptr)
Tries to find the actors with the given tag (returns all found).
Declaration
public static Array<Actor* > FindActors(const Tag& tag, const bool activeOnly=false, Actor* root=nullptr)
Parameters
|
Tag
tag
The tag of the actor to search for. |
|
bool
activeOnly
Find only active actors. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Array<Actor >
Found actors or empty if none. |
FindActorsByParentTag(const Tag& parentTag, const bool activeOnly=false, Actor* root=nullptr)
Search actors using a parent parentTag.
Declaration
public static Array<Actor* > FindActorsByParentTag(const Tag& parentTag, const bool activeOnly=false, Actor* root=nullptr)
Parameters
|
Tag
parentTag
The tag to search actors with subtags belonging to this tag |
|
bool
activeOnly
Find only active actors. |
|
Actor
root
The custom root actor to start searching from (hierarchical), otherwise null to search all loaded scenes. |
Returns
|
Array<Actor >
Returns all actors that have subtags belonging to the given parent parentTag |
FindScene(const Guid& id)
Tries to find scene with given ID.
Declaration
public static Scene* FindScene(const Guid& id)
Parameters
|
Guid
id
Scene id. |
Returns
|
Scene
Found scene or null. |
FindScript()
Tries to find the script of the given type in all the loaded scenes.
Declaration
public static T* FindScript()
Returns
|
T
Script instance if found, null otherwise. |
Type Parameters
|
typename T
|
FindScript(const MClass* type)
Tries to find the script of the given type in all the loaded scenes.
Declaration
public static Script* FindScript(const MClass* type)
Parameters
|
MClass
type
Type of the script to search for. Includes any scripts derived from the type. Supports interface types. |
Returns
|
Script
Found script or null. |
GetActors(const MClass* type, bool activeOnly=false)
Finds all the actors of the given type in all the loaded scenes.
Declaration
public static Array<Actor* > GetActors(const MClass* type, bool activeOnly=false)
Parameters
|
MClass
type
Type of the actor to search for. Includes any actors derived from the type. |
|
bool
activeOnly
Finds only active actors in the scene. |
Returns
|
Array<Actor >
Found actors list. |
GetLastSceneLoadTime()
Gets the last scene load time (in UTC).
Declaration
public static DateTime GetLastSceneLoadTime()
Returns
|
DateTime
Last scene load time |
GetLayerIndex(const StringView& layer)
Gets the zero-based index of the layer.
Declaration
public static int32 GetLayerIndex(const StringView& layer)
Parameters
|
StringView
layer
|
Returns
|
int32
|
GetLayerName(const int32 layerIndex)
Gets the name of the layer based on the index.
Declaration
public static StringView GetLayerName(const int32 layerIndex)
Parameters
|
int32
layerIndex
The index to find the layer string. 0 - 32. |
Returns
|
StringView
The layer string. Returns a blank string if index not found. |
GetNonEmptyLayerNamesCount()
Gets the amount of non empty layer names (from the beginning, trims the last ones).
Declaration
public static int32 GetNonEmptyLayerNamesCount()
Returns
|
int32
The layers count. |
GetScene(int32 index)
Gets the scene.
Declaration
public static Scene* GetScene(int32 index)
Parameters
|
int32
index
The index. |
Returns
|
Scene
The scene object (loaded). |
GetScenes(Array<Actor* >& scenes)
Gets the scenes (as actors).
Declaration
public static void GetScenes(Array<Actor* >& scenes)
Parameters
|
Array<Actor >
scenes
The scenes. |
GetScenes(Array<Guid>& scenes)
Gets the scene ids.
Declaration
public static void GetScenes(Array<Guid>& scenes)
Parameters
|
Array<Guid>
scenes
The scene ids. |
GetScenes(Array<Scene* >& scenes)
Gets the scenes.
Declaration
public static void GetScenes(Array<Scene* >& scenes)
Parameters
|
Array<Scene >
scenes
The scenes. |
GetScenesCount()
Gets the scenes count.
Declaration
public static int32 GetScenesCount()
Returns
|
int32
|
GetScripts(const MClass* type, Actor* root=nullptr)
Finds all the scripts of the given type in an actor or all the loaded scenes.
Declaration
public static Array<Script* > GetScripts(const MClass* type, Actor* root=nullptr)
Parameters
|
MClass
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
|
Array<Script >
Found scripts list. |
IsAnyActionPending()
Checks if any scene action is pending
Declaration
public static bool IsAnyActionPending()
Returns
|
bool
True if scene action will be performed during next update, otherwise false |
IsAnyActorInGame()
Checks if any scene has any actor
Declaration
public static bool IsAnyActorInGame()
Returns
|
bool
True if any scene as any actor, otherwise false |
IsAnySceneLoaded()
Checks if any scene has been loaded. Loaded scene means deserialized and added to the scenes collection.
Declaration
public static bool IsAnySceneLoaded()
Returns
|
bool
|
LoadScene(const Guid& id)
Loads scene from the asset.
Declaration
public static bool LoadScene(const Guid& id)
Parameters
|
Guid
id
Scene ID |
Returns
|
bool
True if loading cannot be done, otherwise false. |
LoadSceneAsync(const Guid& id)
Loads scene from the asset. Done in the background.
Declaration
public static bool LoadSceneAsync(const Guid& id)
Parameters
|
Guid
id
Scene ID |
Returns
|
bool
True if loading cannot be done, otherwise false. |
LoadSceneFromBytes(const BytesContainer& data)
Loads scene from the bytes.
Declaration
public static Scene* LoadSceneFromBytes(const BytesContainer& data)
Parameters
|
BytesContainer
data
The scene data to load. |
Returns
|
Scene
Loaded scene object, otherwise null if cannot load data (then see log for more information). |
ReloadScriptsAsync()
Reloads scripts. Done in the background.
Declaration
public static void ReloadScriptsAsync()
SaveAllScenes()
Saves all scenes to the assets.
Declaration
public static bool SaveAllScenes()
Returns
|
bool
True if action cannot be done, otherwise false. |
SaveAllScenesAsync()
Saves all scenes to the assets. Done in the background.
Declaration
public static void SaveAllScenesAsync()
SaveScene(Scene* scene, bool prettyJson=true)
Saves scene to the asset.
Declaration
public static bool SaveScene(Scene* scene, bool prettyJson=true)
Parameters
|
Scene
scene
Scene to serialize. |
|
bool
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
|
bool
True if action cannot be done, otherwise false. |
SaveSceneAsync(Scene* scene)
Saves scene to the asset. Done in the background.
Declaration
public static void SaveSceneAsync(Scene* scene)
Parameters
|
Scene
scene
Scene to serialize. |
SaveSceneToBytes(Scene* scene, bool prettyJson=true)
Saves scene to the bytes.
Declaration
public static Array<byte> SaveSceneToBytes(Scene* scene, bool prettyJson=true)
Parameters
|
Scene
scene
Scene to serialize. |
|
bool
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
|
Array<byte>
The result data or empty if failed. |
SaveSceneToBytes(Scene* scene, rapidjson_flax::StringBuffer& outData, bool prettyJson=true)
Saves scene to the bytes.
Declaration
public static bool SaveSceneToBytes(Scene* scene, rapidjson_flax::StringBuffer& outData, bool prettyJson=true)
Parameters
|
Scene
scene
Scene to serialize. |
|
rapidjson_flax::StringBuffer
outData
The result data. |
|
bool
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
|
bool
True if action cannot be done, otherwise false. |
ScriptsReloadRegisterObject(ScriptingObject*& obj)
Adds object to preserve during scripts reload. Called during ScriptsReloadStart event to serialize and destroy the object that should be restored when scripts reload ends.
Declaration
public static void ScriptsReloadRegisterObject(ScriptingObject*& obj)
Parameters
|
ScriptingObject
obj
Reference to the object to preserve during the scripting reload. |
SpawnActor(Actor* actor)
Spawn actor on the scene
Declaration
public static bool SpawnActor(Actor* actor)
Parameters
|
Actor
actor
Actor to spawn |
Returns
|
bool
True if action cannot be done, otherwise false. |
SpawnActor(Actor* actor, Actor* parent)
Spawns actor on the scene.
Declaration
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
|
bool
True if action cannot be done, otherwise false. |
UnloadAllScenes()
Unloads all scenes.
Declaration
public static bool UnloadAllScenes()
Returns
|
bool
True if action cannot be done, otherwise false. |
UnloadAllScenesAsync()
Unloads all scenes. Done in the background.
Declaration
public static void UnloadAllScenesAsync()
UnloadScene(Scene* scene)
Unloads given scene.
Declaration
public static bool UnloadScene(Scene* scene)
Parameters
|
Scene
scene
|
Returns
|
bool
True if action cannot be done, otherwise false. |
UnloadSceneAsync(Scene* scene)
Unloads given scene. Done in the background.
Declaration
public static void UnloadSceneAsync(Scene* scene)
Parameters
|
Scene
scene
|