Search Unity

Bug null reference exception on agent.cs 1145 UpdateSensors Function

Discussion in 'ML-Agents' started by Digineaux, Jul 7, 2023.

  1. Digineaux

    Digineaux

    Joined:
    Jul 19, 2015
    Posts:
    18
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.MLAgents.Agent.UpdateSensors () (at C:/CustomFolder/creative/development/Python Stuff/ml-agents-release_20/com.unity.ml-agents/Runtime/Agent.cs:1145)
    3. Unity.MLAgents.Agent.NotifyAgentDone (Unity.MLAgents.Agent+DoneReason doneReason) (at C:/CustomFolder/creative/development/Python Stuff/ml-agents-release_20/com.unity.ml-agents/Runtime/Agent.cs:599)
    4. Unity.MLAgents.Agent.EndEpisodeAndReset (Unity.MLAgents.Agent+DoneReason reason) (at C:/CustomFolder/creative/development/Python Stuff/ml-agents-release_20/com.unity.ml-agents/Runtime/Agent.cs:828)
    5. Unity.MLAgents.Agent.EndEpisode () (at C:/CustomFolder/creative/development/Python Stuff/ml-agents-release_20/com.unity.ml-agents/Runtime/Agent.cs:803)
    6. CreatureAgent.HungerDrain (System.Single amount) (at Assets/A1Core/CreatureAgent.cs:85)
    7. CreatureAgent.Update () (at Assets/A1Core/CreatureAgent.cs:80)
    8.  
    I have not edited agent.cs i extended it for my custom agent. This line looks like its suppossed to loop through sensors and update them to the neaural net. My agnet has a ray perception sensor2d i presume is part ofthe issue. as it seem to work without error without it.
    The lines in my Creture agent script correspond to:
    Code (CSharp):
    1.     private void Update()
    2.     {
    3.         HungerDrain(hungerDrain);
    4.     }
    5.     void HungerDrain(float amount)
    6.     {
    7.         hunger -= amount * Time.deltaTime;
    8.         if (hunger < 0) { EndEpisode(); }
    9.     }
    i also get an errror in the python console less than a minute into training. Though training appears to continue within unity, despite not being connected to the python env:
    Code (CSharp):
    1. (UnityML) C:\CustomFolder\creative\development\Python Stuff\ml-agents-release_20>mlagents-learn config\ppo\Creature.yaml --run-id=test --force
    2.  
    3.             ┐  ╖
    4.         ╓╖╬│╡  ││╬╖╖
    5.     ╓╖╬│││││┘  ╬│││││╬╖
    6. ╖╬│││││╬╜        ╙╬│││││╖╖                               ╗╗╗
    7. ╬╬╬╬╖││╦╖        ╖╬││╗╣╣╣╬      ╟╣╣╬    ╟╣╣╣             ╜╜╜  ╟╣╣
    8. ╬╬╬╬╬╬╬╬╖│╬╖╖╓╬╪│╓╣╣╣╣╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╒╣╣╖╗╣╣╣╗   ╣╣╣ ╣╣╣╣╣╣ ╟╣╣╖   ╣╣╣
    9. ╬╬╬╬┐  ╙╬╬╬╬│╓╣╣╣╝╜  ╫╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╟╣╣╣╙ ╙╣╣╣  ╣╣╣ ╙╟╣╣╜╙  ╫╣╣  ╟╣╣
    10. ╬╬╬╬┐     ╙╬╬╣╣      ╫╣╣╣╬      ╟╣╣╬    ╟╣╣╣ ╟╣╣╬   ╣╣╣  ╣╣╣  ╟╣╣     ╣╣╣┌╣╣╜
    11. ╬╬╬╜       ╬╬╣╣      ╙╝╣╣╬      ╙╣╣╣╗╖╓╗╣╣╣╜ ╟╣╣╬   ╣╣╣  ╣╣╣  ╟╣╣╦╓    ╣╣╣╣╣
    12. ╙   ╓╦╖    ╬╬╣╣   ╓╗╗╖            ╙╝╣╣╣╣╝╜   ╘╝╝╜   ╝╝╝  ╝╝╝   ╙╣╣╣    ╟╣╣╣
    13.    ╩╬╬╬╬╬╬╦╦╬╬╣╣╗╣╣╣╣╣╣╣╝                                             ╫╣╣╣╣
    14.       ╙╬╬╬╬╬╬╬╣╣╣╣╣╣╝╜
    15.           ╙╬╬╬╣╣╣╜
    16.              ╙
    17.  
    18. Version information:
    19.   ml-agents: 0.30.0,
    20.   ml-agents-envs: 0.30.0,
    21.   Communicator API: 1.5.0,
    22.   PyTorch: 2.0.1+cu118
    23. [INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor.
    24. [INFO] Connected to Unity environment with package version 2.3.0-exp.3 and communication version 1.5.0
    25. Traceback (most recent call last):
    26.   File "C:\Users\kodax\anaconda3\envs\UnityML\Scripts\mlagents-learn-script.py", line 33, in <module>
    27.     sys.exit(load_entry_point('mlagents', 'console_scripts', 'mlagents-learn')())
    28.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\learn.py", line 264, in main
    29.     run_cli(parse_command_line())
    30.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\learn.py", line 260, in run_cli
    31.     run_training(run_seed, options, num_areas)
    32.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\learn.py", line 136, in run_training
    33.     tc.start_learning(env_manager)
    34.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents-envs\mlagents_envs\timers.py", line 305, in wrapped
    35.     return func(*args, **kwargs)
    36.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\trainer_controller.py", line 172, in start_learning
    37.     self._reset_env(env_manager)
    38.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents-envs\mlagents_envs\timers.py", line 305, in wrapped
    39.     return func(*args, **kwargs)
    40.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\trainer_controller.py", line 105, in _reset_env
    41.     env_manager.reset(config=new_config)
    42.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\env_manager.py", line 68, in reset
    43.     self.first_step_infos = self._reset_env(config)
    44.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\subprocess_env_manager.py", line 446, in _reset_env
    45.     ew.previous_step = EnvironmentStep(ew.recv().payload, ew.worker_id, {}, {})
    46.   File "c:\customfolder\creative\development\python stuff\ml-agents-release_20\ml-agents\mlagents\trainers\subprocess_env_manager.py", line 101, in recv
    47.     raise env_exception
    48. mlagents_envs.exception.UnityTimeOutException: The Unity environment took too long to respond. Make sure that :
    49.          The environment does not need user interaction to launch
    50.          The Agents' Behavior Parameters > Behavior Type is set to "Default"
    51.         The environment and the Python interface have compatible versions.
    52.         If you're running on a headless server without graphics support, turn off display by either passing --no-graphics option or build your Unity executable as server build.
     
  2. unity_DC4E6570B5CA6DEAD681

    unity_DC4E6570B5CA6DEAD681

    Joined:
    Apr 7, 2024
    Posts:
    1
    Same problem here