Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Load a scene from another scene, mlagents

Discussion in 'Scripting' started by henrik9999, Feb 9, 2024.

  1. henrik9999

    henrik9999

    Joined:
    Sep 9, 2022
    Posts:
    2
    Hi I am using ML-Agents to control a robot in unity through its LLA.
    Is there a way to reload a scene from another scene like this:

    Code (CSharp):
    1. Scene A (master scene):
    2. public void OnEpisodeBegin()
    3.       {
    4.       if (SampleScene exists) {
    5.             SceneManager.UnloadSceneAsync("SampleScene");
    6.       }
    7.       SceneManager.LoadScene("SampleScene", LoadSceneMode.Additive);
    8.       // Wait until the scene is loaded
    9.        
    10.       robot = GameObject.Find("Robot_gameObject"); // Robot in SampleScene
    11.       robot_script = robot.GetComponent<Robot>();
    12.       robot_script.Initialize()
    13.       };
    14.  
    15.  
    16.  
    17. Scene SampleScene:
    18. public void Initialize{
    19.       //Do something
    20. }
    Everything works if I don't load and unload the scene, but I need to restart the scene to restart the physics. The idea for this comes from:
    https://forum.unity.com/threads/reset-physics.862081/
    https://github.com/Unity-Technologies/ml-agents/issues/1122
    Thanks in advance