Hi.
I’m making something for my brother but I can’t figure out something with ML Agents. I’m using the latest version but getting this error:
Assets/Scenes/Scripts/Escape.cs(20,26): error CS0115: 'MovetoGoal.OnActionRecieved(ActionBuffers)': no suitable method found to override
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;
public class MovetoGoal : Agent {
// Start is called before the first frame update
[SerializeField] private Transform targetTransform;
public override void OnEpisodeBegin(){
transform.position = new Vector3(0, 0, 0);
}
//error no function to override on action recieved
public override void CollectObservations(VectorSensor sensor) {
sensor.AddObservation(transform.position);
sensor.AddObservation(targetTransform.position);
}
public override void OnActionRecieved(ActionBuffers actions) {
float moveX = actions.ContinuousActions[0];
float moveZ = actions.ContinuousActions[1];
float moveSpeed = 1f;
transform.position += new Vector3(moveX, 0, moveZ) * Time.deltaTime * moveSpeed;
}
private void OnTriggerEnter(Collider other) {
if (other.TryGetComponent<Goal>(out Goal goal)){
SetReward(1f);
EndEpisode();
}
if (other.TryGetComponent<Wall>(out Wall wall)){
SetReward(-1f);
EndEpisode();
}
}
}
Thanks in advance