Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Resolved How to stop agent from automatically respawning?

Discussion in 'ML-Agents' started by snuwman, Apr 8, 2021.

  1. snuwman

    snuwman

    Joined:
    Jul 6, 2020
    Posts:
    2
    Basically I have a project setup similar to the Unity's "Pyramid" example. The thing is that in my game agents respawn with a delay: agent dies -> 10 seconds not present in game -> spawns at random coordinates. I tried finding a way to prevent Academy from calling OnEpisodeBegin() before the 10 seconds have passed, but didn't find a way. I also tried googling, but didn't find anything. Could someone explain, how exactly does the whole Academy cycle thing work and how to control/override it?

    Many thanks.
     
  2. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    I'm assuming you're using a DecisionRequester component on your agent? The component requests decisions and actions automatically, based on Academy steps. When it keeps requesting decisions after an episode has ended, OnEpisodeBegin() is invoked again right away.

    AFAIK, you can work around this in one of the following ways:
    1) Destroy the DecisionRequester component when the episode ends and re-add one when your respawn logic is complete.
    2) Extend https://github.com/Unity-Technologi....unity.ml-agents/Runtime/DecisionRequester.cs and override ShouldRequestDecision() in order to enable/disable requests to fit your needs.
    3) Write your own decision requester code and disable automatic stepping altogether, see https://forum.unity.com/threads/brain-update-control.1043317/
     
    Last edited: Apr 9, 2021
    snuwman likes this.
  3. snuwman

    snuwman

    Joined:
    Jul 6, 2020
    Posts:
    2
    Thanks! That's exactly what I was looking for.