Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question OnActionReceived(float[])': no suitable method found to override

Discussion in 'ML-Agents' started by wumingwangyi, Jan 4, 2023.

  1. wumingwangyi

    wumingwangyi

    Joined:
    Dec 13, 2022
    Posts:
    1
    I have met these problems when editing script:
    error CS0115: 'JuggleAgent.OnEpsiodeBegin()': no suitable method found to override

    I use unity v2021, ml-agent 2.3.0, python 3.9

    And following is code
    using UnityEngine;
    using Unity.MLAgents;
    using Unity.MLAgents.Sensors;
    using UnityEditor.AnimatedValues;
    using Unity.MLAgents.Actuators;
    public class JuggleAgent: Agent
    {
    public Rigidbody ball;
    Rigidbody player;
    public float speed = 30.0f;
    float diff = 0.0f;
    float previousDiff = 0.0f;
    float previousY = 5.0f;
    bool collied = false;

    public override void OnActionReceived(ActionBuffers vectorAction)
    {
    Vector3 controlSignal = Vector3.zero;
    print("vectorAction");
    //controlSignal.x = vectorAction[0];
    //controlSignal.z = vectorAction[1];
    //if (player.transform.localPosition.y == 1.0f)
    //{
    // controlSignal.y = vectorAction[2] *10.0f;
    //}
    player.AddForce(controlSignal * speed);
    diff = ball.transform.localPosition.y - previousY;
    if(diff > 0 && previousDiff < 0 && collied)
    {
    AddReward(0.1f);
    }
    collied = false;
    previousDiff = diff;
    previousY = ball.transform.localPosition.y;
    if (ball.transform.localPosition.y < 1.5f ||
    Mathf.Abs(ball.transform.localPosition.x) > 10.0f ||
    Mathf.Abs(ball.transform.localPosition.z) > 10.0f)
    {
    EndEpisode();
    }
    }
    private void OnCollisionEnter(Collision collision)
    {
    if(collision.rigidbody == ball)
    {
    collied = true;
    }
    }
    public override void OnEpsiodeBegin()
    {
    ball.transform.localPosition = new Vector3(Random.value * 10 - 5, 5.0f, Random.value * 10 - 5);
    ball.velocity = Vector3.zero;
    ball.rotation = Quaternion.Euler(Vector3.zero);
    ball.angularVelocity = Vector3.zero;
    player.transform.localPosition = Vector3.up;
    player.velocity = Vector3.zero;
    player.rotation = Quaternion.Euler(Vector3.zero);
    player.angularVelocity = Vector3.zero;
    diff = 0.0f;
    previousDiff = 0.0f;
    previousY = 5.0f;
    collied = false;
    }
    }
     
    Last edited: Jan 4, 2023
  2. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    154
    Code (CSharp):
    1. OnEpsiodeBegin()
    is
    Code (CSharp):
    1. OnEpisodeBegin()