Skip to content

Commit b5151fa

Browse files
author
Chris Elion
authored
Fix heuristic example and some crefs (#4690)
1 parent 21a761a commit b5151fa

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void CopyActions(ActionBuffers actionBuffers)
9898
/// * <see cref="BehaviorType.InferenceOnly"/>: decisions are always made using the trained
9999
/// model specified in the <see cref="BehaviorParameters"/> component.
100100
/// * <see cref="BehaviorType.HeuristicOnly"/>: when a decision is needed, the agent's
101-
/// <see cref="Heuristic"/> function is called. Your implementation is responsible for
101+
/// <see cref="Heuristic(in ActionBuffers)"/> function is called. Your implementation is responsible for
102102
/// providing the appropriate action.
103103
///
104104
/// To trigger an agent decision automatically, you can attach a <see cref="DecisionRequester"/>
@@ -109,7 +109,7 @@ public void CopyActions(ActionBuffers actionBuffers)
109109
/// can only take an action when it touches the ground, so several frames might elapse between
110110
/// one decision and the need for the next.
111111
///
112-
/// Use the <see cref="OnActionReceived(float[])"/> function to implement the actions your agent can take,
112+
/// Use the <see cref="OnActionReceived(ActionBuffers)"/> function to implement the actions your agent can take,
113113
/// such as moving to reach a goal or interacting with its environment.
114114
///
115115
/// When you call <see cref="EndEpisode"/> on an agent or the agent reaches its <see cref="MaxStep"/> count,
@@ -125,7 +125,7 @@ public void CopyActions(ActionBuffers actionBuffers)
125125
/// only use the [MonoBehaviour.Update] function for cosmetic purposes. If you override the [MonoBehaviour]
126126
/// methods, [OnEnable()] or [OnDisable()], always call the base Agent class implementations.
127127
///
128-
/// You can implement the <see cref="Heuristic"/> function to specify agent actions using
128+
/// You can implement the <see cref="Heuristic(in ActionBuffers)"/> function to specify agent actions using
129129
/// your own heuristic algorithm. Implementing a heuristic function can be useful
130130
/// for debugging. For example, you can use keyboard input to select agent actions in
131131
/// order to manually control an agent's behavior.
@@ -293,7 +293,7 @@ internal struct AgentParameters
293293

294294
/// <summary>
295295
/// VectorActuator which is used by default if no other sensors exist on this Agent. This VectorSensor will
296-
/// delegate its actions to <see cref="OnActionReceived(float[])"/> by default in order to keep backward compatibility
296+
/// delegate its actions to <see cref="OnActionReceived(ActionBuffers)"/> by default in order to keep backward compatibility
297297
/// with the current behavior of Agent.
298298
/// </summary>
299299
IActuator m_VectorActuator;
@@ -630,7 +630,7 @@ public int CompletedEpisodes
630630
/// Use <see cref="AddReward(float)"/> to incrementally change the reward rather than
631631
/// overriding it.
632632
///
633-
/// Typically, you assign rewards in the Agent subclass's <see cref="OnActionReceived(float[])"/>
633+
/// Typically, you assign rewards in the Agent subclass's <see cref="OnActionReceived(ActionBuffers)"/>
634634
/// implementation after carrying out the received action and evaluating its success.
635635
///
636636
/// Rewards are used during reinforcement learning; they are ignored during inference.
@@ -859,11 +859,12 @@ public virtual void Initialize() { }
859859
/// You can also use the [Input System package], which provides a more flexible and
860860
/// configurable input system.
861861
/// <code>
862-
/// public override void Heuristic(ActionBuffers actionsOut)
862+
/// public override void Heuristic(in ActionBuffers actionsOut)
863863
/// {
864-
/// actionsOut.ContinuousActions[0] = Input.GetAxis("Horizontal");
865-
/// actionsOut.ContinuousActions[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
866-
/// actionsOut.ContinuousActions[2] = Input.GetAxis("Vertical");
864+
/// var continuousActionsOut = actionsOut.ContinuousActions;
865+
/// continuousActionsOut[0] = Input.GetAxis("Horizontal");
866+
/// continuousActionsOut[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
867+
/// continuousActionsOut[2] = Input.GetAxis("Vertical");
867868
/// }
868869
/// </code>
869870
/// [Input Manager]: https://docs.unity3d.com/Manual/class-InputManager.html

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public virtual void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker
1414
}
1515

1616
/// <summary>
17-
/// This method passes in a float array that is to be populated with actions.
17+
/// Deprecated, use <see cref="Heuristic(in ActionBuffers)"/> instead.
1818
/// </summary>
1919
/// <param name="actionsOut"></param>
2020
public virtual void Heuristic(float[] actionsOut)
@@ -35,7 +35,7 @@ public virtual void OnActionReceived(float[] vectorAction) { }
3535
/// <returns>
3636
/// The last action that was decided by the Agent (or null if no decision has been made).
3737
/// </returns>
38-
/// <seealso cref="OnActionReceived(float[])"/>
38+
/// <seealso cref="OnActionReceived(ActionBuffers)"/>
3939
// [Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers, Or GetStoredDiscreteActions.")]
4040
public float[] GetAction()
4141
{

0 commit comments

Comments
 (0)