GameObjectFlags DontDestroyOnLoad

robot_2Generated
code_blocksInput

Description

The DontDestroyOnLoad flag is a member of the GameObjectFlags enumeration in the Sandbox API. This flag is used to indicate that a game object should remain active and not be destroyed when a new scene is loaded. This is particularly useful for objects that need to persist across different scenes, such as game managers or player data objects.

Usage

To use the DontDestroyOnLoad flag, you can set it on a GameObject to ensure that it remains active when transitioning between scenes. This is done by modifying the flags of the game object to include DontDestroyOnLoad.

Example

// Example of using DontDestroyOnLoad flag
GameObject myPersistentObject = new GameObject();
myPersistentObject.Flags |= GameObjectFlags.DontDestroyOnLoad;

// Now, myPersistentObject will not be destroyed when a new scene is loaded.