Search Unity

Question Is it possible to switch brains during training?

Discussion in 'ML-Agents' started by StewedHarry, Jul 29, 2020.

  1. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    I want to set up two behaviours for one agent. One behaviour would be a patrolling type behaviour, and the other would be a 'something has been detected' behaviour.

    Is this possible and, if so, what would the best way of achieving this be?

    I was thinking of creating and training two agents separately and then having them perform inference in a scenario, but then instantiate/destroy them at the right moment so it would look as though the same agent changed behaviours. This would allow each behaviour to have it's own unique set of observations, but would force them to train separately.
     
  2. Hsgngr

    Hsgngr

    Joined:
    Dec 28, 2015
    Posts:
    61
    Yes it is, I recommend you to look the wallJump example in the example environment of mlagent repo. It uses 2 brains
     
  3. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    I have looked at it. It switches between the brains during inference, not during training
     
  4. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    473
    Training two distinct agents should work for this. You could implement the physics in a separate class, so that both your agents receive observations from, and send actions to that common physics interface. Then it's just a matter of calling RequestDecision/Action on whatever agent behaviour is applicable during inference. Some controller script would decide which agent is active or inactive depending on the situation, without having to instantiate or destroy any agents.
     
  5. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    So could I attach two agent scripts to the same gameobject? I'm not sure how I'd switch between the two scripts during inference
     
  6. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    I have only ever used the decision requester component to request decisions. I guess I could do it manually and switch between them where appropriate
     
    Hsgngr likes this.