This is my first time making a neural network, I have do a research about it and saw a video about a neural network that control a bunch of cars and learn from it mistake.
The problem is that when I press play the console show that there is a NullReferenceException error, of course I know what it is, but the thing is I have check all the code that related to it, or maybe I not checked enough to see the error. I also have writedown the GetComponent in Awake() to test if it going to work, but it did not.
The error line is in double[] controlInputs = Agent.FNN.ProcessInputs(sensorOutput)
private void FixedUpdate()
{
// Get control inputs from Agent
if (!UseUserInput)
{
// Get readings from sensors
double[] sensorOutput = new double[sensors.Length];
for (int i = 0; i < sensors.Length; i++)
{
sensorOutput[i] = sensors[i].Output;
}
double[] controlInputs = Agent.FNN.ProcessInputs(sensorOutput);
Movement.SetInputs(controlInputs);
}
if(timeSinceLastCheckpoint > MAX_CHECKPOINT_DELAY)
{
Die();
}
}
Another thing is, I have attach the script to Unity and enable debugging, the debugging process show that the Agent script is already null in the beginning of the script
Here the code snippet:
public Agent Agent { get; set; }
public float CurrentCompletionReward
{
get { return Agent.Genotype.Evaluation; }
set { Agent.Genotype.Evaluation = value; }
}
Also the CurrentCompletionReward also have a NullReferenceException while debugging, still I have checked all the related to the it, but it is still having the same error.
The code that related to CurrentCompletionReward is in another script called TrackManager and only inside the Update() method:
private void Update()
{
// Update reward for each enabled car on the track
for (int i = 0; i < cars.Count; i++)
{
RaceCar car = cars[i];
if (car.Car.enabled)
{
car.Car.CurrentCompletionReward = GetCompletePerc(car.Car, ref car.CheckpointIndex);
// Update best
if(BestCar == null || car.Car.CurrentCompletionReward >= BestCar.CurrentCompletionReward)
{
BestCar = car.Car;
}
else if (SecondBestCar == null || car.Car.CurrentCompletionReward >= SecondBestCar.CurrentCompletionReward)
{
SecondBestCar = car.Car;
}
}
}
}
I really need help, thanks for helping
I have tried to debugging the whole project and also do research on the current problem
Vuong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.