# Scenarios Scenarios have three responsibilities: 1. Controlling the execution flow of your simulation 2. Organizing a list of Randomizers 3. Defining settings that can be configured externally from a built Unity player By default, the Perception package includes one ready-made Scenario, the `FixedLengthScenario` class. This Scenario runs each Iteration for a fixed number of frames and is compatible with the Run in Unity Simulation window for cloud simulation execution. ## Scenario Lifecycle Hooks Scenarios have a number of lifecycle hooks that are called during execution. Below is a diagram visualizing the sequence of operations run by a typical scenario:
## JSON Configuration Scenarios can be serialized to JSON, modified, and imported at runtime to configure simulation behavior even after a Unity player has been built. The following scenario settings can be serialized by default using the "Generate JSON Config" button on the scenario inspector: 1. Scenario constants 2. String, numeric, and boolean fields on Randomizers and Parameters 3. Constant, Uniform, and Normal sampler configurations Here is an example of how to load a Scenario JSON configuration into a Windows Unity player using the `--scenario-config-file` flag: `.\PerceptionTutorial.exe --scenario-config-file scenarioConfiguration.json` ## Scenario Cloud Execution (Unity Simulation) Users can utilize Unity's Unity Simulation service to execute a Scenario in the cloud through the perception package's Run in Unity Simulation window. To open this window from the Unity editor using the top menu bar, navigate to `Window -> Run in Unity Simulation`. NOTE: To execute a Scenario using the Run in Unity Simulation window, the Scenario class must implement the UnitySimulationScenario class. From the newly opened editor window, customize the following settings to configure a new Unity Simulation run: 1. **Run Name** - the name of the Unity Simulation run (example: TestRun0) 2. **Total Iterations** - The number of Scenario Iterations to complete during the run 3. **Instance Count** - The number of Unity Simulation worker instances to distribute execution between 4. **Sys-Param** - The system parameters or the hardware configuration of Unity Simulation worker instances to execute the Scenario with. Determines per instance specifications such as the number of CPU cores, amount of memory, and presence of a GPU for accelerated execution. 5. **Json Configuration** - This field is optional. You can select a json scenario configuration within your project to configure your Unity Simulation run instead of using the Scenario settings presently configured in the Editor. ## Implementing Custom Scenarios For use cases where the Scenario should run for an arbitrary number of frames, implementing a custom Scenario may be necessary. Below are the two most common Scenario properties a user might want to override to implement custom Scenario Iteration conditions: 1. **isScenarioReadyToStart** - defines the conditions that determine when a Scenario can begin iterating 1. **isIterationComplete** - defines the conditions that determine the end of a Scenario iteration 2. **isScenarioComplete** - defines the conditions that determine the a Scenario to stop iterating ### Abstract Scenario Classes There are a few abstract scenario classes to choose from depending on your requirements when deriving a custom scenario. Below is a list of these options and when it is appropriate to derive them for your use case: 1. **Scenario