Sandbox Framework uses subsystem to make things easier for developers. Subsystems are automcatically instanced with managed lifetime and can be easily accessed from Blueprint or C++. There are 2 subsystems included with Sandbox Framework and they are Sandbox World Subsystem and Sandbox Graph Subsystem.
Sandbox World Subsystem
This subsystem is inherited from UWorldSubsystem and is automatically initialized upon map load and deinitialized upon map unload and is used to interact with Sandbox supported actors in world. Here is a quick overview of this subsystem.
- Spawn Sandbox Asset in world.
- Add/Remove gameplay tags to/from sandbox supported actors.
- Switch between Sandbox play and edit modes.
To spawn a sandbox supported actor, always use Spawn Actor from Asset function under Sandbox World Subsystem.
DO NOT USE the default spawn actor node in Blueprint or UWorld::SpawnActor in C++.
USandboxWorldSubsystem* SandboxWorldSubsystem = GetWorld()->GetSubsystem<USandboxWorldSubsystem>();
Shown below are functions provided to switch between Play, Edit mode and check what mode we are currently on.
This subsystem also provides two functions for validating assets at runtime to make sure they are ready for gameplay although this is completely optional. When executed, the validation function will iterate through all sandbox actors and execute On Validate Asset function (In C++ it is called K2_OnValidateAsset) which the developer can override to provide validation rule.
Below is an example actor implementing validation rule in Blueprint which makes sure a specific tag is set properly.
Sandbox Graph Subsystem
This subsystem is inherited from UGameInstanceSubsystem and is automatically initialized upon game start and deinitalized before exiting the game. This subsystem is designed to interact with Sandbox Graph. Here is a quick overview of this subsytem.
• Manages lifetime of Sandbox Graphs.
• Connects Snadbox Graphs with Sandbox supported actors.
• Provides delegates for various Sandbox specific events.
To call a specific node in your Sandbox Graph Asset you can use Start Graph Event node with your desired event name. Here is an example screenshot showing how to call a custom node Sandbox Graph Asset externally from Blueprint.
But the limitation with the above method is you cannot pass inputs to the graph. To pass inputs, you have to use Start Graph Event with Value where value can be anything listed below.
• Gameplay Tag Container
• Gameplay Tag
Here is an example screenshot showing how to pass input to Sandbox Graph Node.
To complete the graph at anytime you can call Finish Sandbox Graph from Sandbox Graph Subsystem.