For some reason, the code doesnt have any method groups, but when I use it in Unity, it shows an errror saying that it’s unable to assign to OnEpisodeBegin because it’s a method group. Is anyone able to fix this?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class AgentScript : Agent
{
public float moveSpeed = 5f;
public float broadcastRange = 5f;
void Start()
{
OnEpisodeBegin += ResetAgent;
}
void ResetAgent()
{
transform.position = new Vector3(0f, 0f, 0f);
transform.rotation = Quaternion.identity;
}
public override void OnActionReceived(ActionBuffers actions)
{
Vector2 moveDirection = new Vector2(actions.ContinuousActions[0], actions.ContinuousActions[1]).normalized;
GetComponent<Rigidbody2D>().velocity = moveDirection * moveSpeed;
BroadcastMessageToOthers();
}
public override void CollectObservations(VectorSensor sensor) => sensor.AddObservation(transform.position);
void BroadcastMessageToOthers()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, broadcastRange);
foreach (Collider2D collider in colliders)
if (collider.gameObject != gameObject)
collider.gameObject.SendMessage("OnBroadcastReceived", SendMessageOptions.DontRequireReceiver);
}
}