Class not recognised?

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…

Layers object is not initialized. In the Awake method, call

Layers = new List<List<Neuron>> ();

Also, even when the List is initialized Layers[0] and Layers[1] will probably be null as well. You have to first add a List to the Layers to be able to access it with index.

Since your Gene class is not a monobehaviour and therefore not serialized, you have to take care of initializing all variables of your class. You never create the “Layers” list and you never create the Lists inside the Layers list. Looks like you don’t have any hidden layers so you only have two layers (0 == input, 1 == output). Furthermore you don’t want to run your loop up to “Capacity” but to “Count”. Count is the actual element count. You can not access elements beyond that, no matter what internal capacity the list uses.

public void Init(int inN, int outN)
{
    Layers = new List<List<Neuron>>();
    Layers.Add(new List<Neuron>()); // 0
    Layers.Add(new List<Neuron>()); // 1
    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.Count; l++)
    {
        for (int i = 0; i < Layers[l].Count; i++)
        {
            Layers[l]*.InitializeNeuron(Layers, l);*

}
}
}
Btw: I’ve written a simple generational neural network for [this question over here][1]. Though it only supports fully connected layers and only forward links and only to the next layer. The hidden layers can be configured as you wish ^^.
[1]: http://answers.unity.com/answers/1205957/view.html