I have a object named Grid and TowerMenu:
public class Grid : MonoBehaviour
{
public TowerMenu TowerMenu;
public void Start()
{
TowerMenu.Grid = this;
}
}
public class TowerMenu
{
public Grid Grid;
public int a;
}
I want to edit the TowerMenu in Inspector so first I need to create it so I added the code in `Assests/Editor/TowerMenuEditor.cs`:
[CustomEditor(typeof(Grid))]
public class TowerMenuEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Grid Grid = target as Grid;
Grid.TowerMenu = new TowerMenu();
}
}
But I get NullReferenceException in Grid.Start about `TowerMenu = null` when I run my game, although the inspector should have created it.
What is the problem here?