Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Need help with "NullReferenceException: Object reference not set to an instance of an object" error

Discussion in 'ML-Agents' started by smoemnk, Aug 21, 2023.

  1. smoemnk

    smoemnk

    Joined:
    Nov 1, 2021
    Posts:
    6
    I'm working on a ML Agents project where the AI learns through behaviour cloning exclusively to park a car. I recently revised the entire Agent script for general optimisation and whatnot, and after doing so I get this error.


    I also can't add the "CarController" script to the "Car Controller" field in the Agent script.



    As you see the names of the scripts match with file name and everything. I have no clue why I have this issue and I've tried finding people with the same issue as me but nothing seems to work.
     
  2. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    100
    where do you define what rb is in the CarController script?
    you can see it is underlined in your IDE which probably means you haven't defined it, you likely forgot to reference it in Start like you did for the CarParkingAgent script
     
    smoemnk likes this.
  3. smoemnk

    smoemnk

    Joined:
    Nov 1, 2021
    Posts:
    6
    is private "Rigidbody rb;" not enough? Do I need to reference GetComponent<Rigidbody>(); in both scripts? Ill try that thankyou for your reply