Here is my whole code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gene
{
public bool init;
public List<List<Neuron>> Layers;
public void Init(int inN, int outN)
{
for (int l = 0; l < inN; l++)
{
Layers[0].Add(new Neuron());
}
for (int l = 0; l < outN; l++)
{
Layers[1].Add(new Neuron());
}
for (int l = 0; l < Layers.Capacity; l++)
{
for (int i = 0; i < Layers[l].Capacity; i++)
{
Layers[l]*.InitializeNeuron(Layers, l);*
}
}
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public float[] feedNetwork(float[] inputs)
{
float[] output = new float[Layers[Layers.Capacity - 1].Capacity];
for (int i = 0; i < inputs.Length; i++)
{
Layers[0].InputVal = inputs*;*
}
for (int i = 0; i < Layers[Layers.Capacity - 1].Capacity; i++)
{
output = Layers[Layers.Capacity - 1].InputVal;
}
return output;
}
}
public class Neuron
{
public float Weight;
public List Connections;
public float InputVal = 0;
public int connectionNumber = 0;
private int connected = 0;
public Neuron()
{
}
public void InitializeNeuron(List<List> choice, int index)
{
Weight = Random.Range(-1, 1);
if (index != choice.Capacity - 1)
{
for (int j = 0; j < choice[index + 1].Capacity - 1; j++)
{
float chanceCon = Random.Range(0, 100);
if (chanceCon < 5)
{
Connections.Add(choice[index + 1][j]);
Connections[Connections.Capacity - 1].connectionNumber += 1;
}
}
}
}
public void FeedFoward()
{
bool go = false;
if (connected != connectionNumber - 1)
{
connected += 1;
}
else
{
go = true;
}
if (go)
{
InputVal = InputVal * Weight;
for (int i = 0; i < Connections.Capacity; i++)
{
Connections*.InputVal += InputVal;*
}
for (int i = 0; i < Connections.Capacity; i++)
{
Connections*.FeedFoward();*
}
}
}
}
I have a class gene that when called to initialise, it creates neurons.
But it when I run the game, Layers[0].Add(new Neuron()); gives an error saying "NullReferenceException: Object reference not set to an instance of an object
Gene.Init (Int32 inN, Int32 outN)"
Sorry for long post and bad formatting and thank you for any help you can give me. I can’t seem to find the error for me neuron is declared properly…