# Scenario State generation

**URL:** https://discourse.kitware.com/t/scenario-state-generation/1536
**Category:** Pulse Physiology Engine
**Created:** [July 24, 2025, 9:24pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536 "2025-07-24T21:24:51Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Ayfel](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Ayfel](https://discourse.kitware.com/u/Ayfel)
#### Post date: [July 24, 2025, 9:24pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/1 "2025-07-24T21:24:51Z")

</div>

So I used to be able to do the following in Unity to create my state but it seems like a lot of these methods are now gone? Any guidance on how to achieve the same?

```auto
public void GenerateEditorStateFromScenario()
        {

            Debug.Log("Using Pulse version " + PulseEngine.Version() + "-" + PulseEngine.Hash());

            string scenarioPath = AssetDatabase.GetAssetPath(initialScenarioFile);

            //The path for the data to create a state
            string pulseDataPath="";

            SEScenarioExec execOpts = new SEScenarioExec();

            var appDirectory = new DirectoryInfo(Application.dataPath);
            
            if (appDirectory.Exists)
            {
                var rootPath = appDirectory.Parent;
                pulseDataPath = $"{CourseHelper.Instance.GetCaffeinePackagePath()}3RD/PulsePhysiologyEngine/Data";
            }

            // Set the directory where Pulse can find its data files (usally bin/install)
            execOpts.SetDataRootDirectory(pulseDataPath);
            // Where do you want any states created by scenarios to go?
            execOpts.SetSerializationDirectory(Application.persistentDataPath + "/" +
                                    gameObject.name + "/states/");
            // Set empty CSV dir if you do not want a csv file
            execOpts.SetDataRequestCSVFilename("");
            //execOpts.SetDataRequestCSVFilename("");
            execOpts.SetLogFilename(Application.persistentDataPath + "/" +
                                    gameObject.name + "/scenarios/PulseScenarioRunner.log");
            execOpts.SetScenarioFilename(scenarioPath);

            //Modify the path to serialize
            JObject scenarioJSON = JObject.Parse(initialScenarioFile.text);
            string newStatePath = Application.dataPath + "/Pulse States/" + initialScenarioFile.name + "_state.json";
            scenarioJSON.SelectToken("..Filename").Replace(newStatePath);

            //Overwrite with new content
            File.WriteAllText(scenarioPath, scenarioJSON.ToString());            

            PulseUnityEngine pulse = new PulseUnityEngine();
            if (!pulse.ExecuteScenario(execOpts))
                Debug.Log("Error running scenario");

            AssetDatabase.Refresh();

            initialState = AssetDatabase.LoadAssetAtPath("Assets" + "/Pulse States/" + initialScenarioFile.name + "_state.json", typeof(TextAsset)) as TextAsset;

        }

```

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 24, 2025, 9:35pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/2 "2025-07-24T21:35:30Z")

</div>

I will need to get Unity up and running to look at this in detail

But have [you looked at this HowTo](https://gitlab.kitware.com/physiology/engine/-/blob/integration/src/csharp/howto/HowTo_RunScenarios.cs)?

---

<div class="post-metadata">

### Author: ![Ayfel](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/a/8e8cbc/32.png) [@Ayfel](https://discourse.kitware.com/u/Ayfel)
#### Post date: [July 24, 2025, 9:38pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/3 "2025-07-24T21:38:41Z")

</div>

That might be the answer, thank you. I’ll try to implement it with that new way.

---

<div class="post-metadata">

### Author: ![ayoub\_Elmendery](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ayoub_elmendery/32/1106_2.png) [@ayoub\_Elmendery](https://discourse.kitware.com/u/ayoub_Elmendery)
#### Post date: [August 4, 2025, 11:05pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/4 "2025-08-04T23:05:11Z")

</div>

Please, I started to use pulse engine in unity, and all i know to do is to run an existing scenario, and now i need to creat my own, can i have some guidance please, and thank you

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 4, 2025, 11:37pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/5 "2025-08-04T23:37:15Z")

</div>

We recommend using the [Pulse Explorer](https://gitlab.kitware.com/physiology/explorer/-/wikis/home) to create and edit scenarios that create a state file that you can load into your Unity application

---

<div class="post-metadata">

### Author: ![ayoub\_Elmendery](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ayoub_elmendery/32/1106_2.png) [@ayoub\_Elmendery](https://discourse.kitware.com/u/ayoub_Elmendery)
#### Post date: [August 6, 2025, 10:50pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/6 "2025-08-06T22:50:40Z")

</div>

okey, thank you

---

<div class="post-metadata">

### Author: ![ayoub\_Elmendery](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ayoub_elmendery/32/1106_2.png) [@ayoub\_Elmendery](https://discourse.kitware.com/u/ayoub_Elmendery)
#### Post date: [August 7, 2025, 9:10am UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/7 "2025-08-07T09:10:33Z")

</div>

Thank you again for your response, i have a second question, in my case, I want to simulate a COPD/pneumonia scenario in which I ask two questions to the participant.

The first question will be to ask them to identify the relevant clinical cues, in this initial state, I need to have specific vitals displayed on the monitor, I believe this would be my **T0 state**.

The second question will ask the participant to perform an action, and these actions should have an effect on the vital signs shown on the monitor.

So, my first question is: **do I only need to use states, or do I need to use a full scenario?**  
And my second question, sorry for asking so much, is: **what is the workflow to create a state file from an edited scenario?**  
In Pulse Explorer, it seems I only have the option to save a scenario, not a state.

Thank you again!

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 7, 2025, 11:48am UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/8 "2025-08-07T11:48:40Z")

</div>

Great questions!!

Your application should use a state file. T0 as you describe it.

You should save the scenario that makes your state into your code repository.  
As Pulse evolves from version to version, the variables in the state file no longer reflect changes in the variables of the new version. We may add new variables that your state does not have. We may remove variables that your state has. Needless to say, it would be quite an undertaking to maintain backwards compatibility of state files.

The solution to this is to save a scenario file that runs Pulse to create your state file.  
Scenarios are also not backwards compatible, but the actions they contain rarely change (but it does happen) but its pretty simple to manually update those files if needed.

But as Pulse is always changing, a model update can affect the expected physiology of your state. So as you upgrade Pulse versions, you should ensure you state files still demonstrate the learning objectives you need. For example, we have been working with subject matter experts to improve our ARDS/COPD models to improve their [validation](https://pulse.kitware.com/_mechanical_ventilator_methodology.html#autotoc_md908). These updates are not in the current Unity asset. They may or may not have impacts on your application learning objectives. (Hopefully for the better, we are putting a lot of effort into this work)

On to your question as to how create states in the explorer. Just use a Serialization action from the actions tab.

 ![image](https://discourse.kitware.com/uploads/default/original/2X/2/26cc168d934f66843482cdb374835e964a9cb683.png)

Once you have a scenario that creates the patient physiology you want along with the serializtion action to create that state for your application, save that scenario out and keep it, so you can rerun it when our next version comes out.

Happy to help!!

---

<div class="post-metadata">

### Author: ![ayoub\_Elmendery](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ayoub_elmendery/32/1106_2.png) [@ayoub\_Elmendery](https://discourse.kitware.com/u/ayoub_Elmendery)
#### Post date: [August 7, 2025, 12:24pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/9 "2025-08-07T12:24:28Z")

</div>

understood Mr.Abray, thank you again

---

<div class="post-metadata">

### Author: ![ayoub\_Elmendery](https://discourse.kitware.com/user_avatar/discourse.kitware.com/ayoub_elmendery/32/1106_2.png) [@ayoub\_Elmendery](https://discourse.kitware.com/u/ayoub_Elmendery)
#### Post date: [August 7, 2025, 11:38pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/10 "2025-08-07T23:38:46Z")

</div>

One of the issues I’m currently facing is related to temperature. In Pulse Explorer, when I save a state, the temperature is 37.1°C. However, when I run the same state using the Pulse Engine Driver in unity, the temperature is 32°C. And when I run a scenario using that same state, the temperature starts to rise and doesn’t stop, it exceeds 50°C.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 7, 2025, 11:48pm UTC](https://discourse.kitware.com/t/scenario-state-generation/1536/11 "2025-08-07T23:48:00Z")

</div>

Can you share your files here?
