Skip to content

Commit 29ee576

Browse files
Made BehaviorType public and added the SetBehaviorType method (#3572)
* Made BehaviorType public and added the SetBehaviorType method * Moving the comments around and making Setting the behaviorType to the same value do nothing
1 parent ffc0254 commit 29ee576

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

com.unity.ml-agents/Runtime/Agent.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,22 @@ public void GiveModel(
363363
m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
364364
}
365365

366+
/// <summary>
367+
/// Updates the type of behavior for the agent.
368+
/// </summary>
369+
/// <param name="behaviorType"> The new behaviorType for the Agent
370+
/// </param>
371+
public void SetBehaviorType(BehaviorType behaviorType)
372+
{
373+
if (m_PolicyFactory.m_BehaviorType == behaviorType)
374+
{
375+
return;
376+
}
377+
m_PolicyFactory.m_BehaviorType = behaviorType;
378+
m_Brain?.Dispose();
379+
m_Brain = m_PolicyFactory.GeneratePolicy(Heuristic);
380+
}
381+
366382
/// <summary>
367383
/// Returns the current step counter (within the current episode).
368384
/// </summary>

com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55

66
namespace MLAgents.Policies
77
{
8+
9+
/// <summary>
10+
/// Defines what type of behavior the Agent will be using
11+
/// - Default : The Agent will use the remote process for decision making.
12+
/// if unavailable, will use inference and if no model is provided, will use
13+
/// the heuristic.
14+
/// - HeuristicOnly : The Agent will always use its heuristic
15+
/// - InferenceOnly : The Agent will always use inference with the provided
16+
/// neural network model.
17+
/// </summary>
18+
[Serializable]
19+
public enum BehaviorType
20+
{
21+
Default,
22+
HeuristicOnly,
23+
InferenceOnly
24+
}
25+
26+
827
/// <summary>
928
/// The Factory to generate policies.
1029
/// </summary>
1130
[AddComponentMenu("ML Agents/Behavior Parameters", (int)MenuGroup.Default)]
1231
internal class BehaviorParameters : MonoBehaviour
1332
{
14-
[Serializable]
15-
enum BehaviorType
16-
{
17-
Default,
18-
HeuristicOnly,
19-
InferenceOnly
20-
}
2133

2234
[HideInInspector]
2335
[SerializeField]
@@ -36,7 +48,7 @@ enum BehaviorType
3648
// and will always have its default value
3749
// This field is set in the custom editor.
3850
#pragma warning disable 0649
39-
BehaviorType m_BehaviorType;
51+
internal BehaviorType m_BehaviorType;
4052
#pragma warning restore 0649
4153
[HideInInspector]
4254
[SerializeField]

0 commit comments

Comments
 (0)