Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Help Wanted 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:
    25
    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:
    53
    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:
    25
    I have looked at it. It switches between the brains during inference, not during training
     
  4. mbaske

    mbaske

    Joined:
    Dec 31, 2017
    Posts:
    254
    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:
    25
    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:
    25
    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.
unityunity