Hey I always get the Error from the title, when i change the scene or stop running the play mode.
When the scene loads the enemy-GameObjects spawn in, from my player-GameObjects, those are in a List. (First code)
When I then destroy a enemy-GameObject, it spawns a player-GameObject and this activates new enemy-GameObjects. And so on.
The error always sends me to the 2nd script. But i think the bug is in the 1st script with the List.
Also when i build the game, everything works perfect
public List<GameObject> EnemyArea = new List<GameObject>();
private void Start()
{
EnemyArea.RemoveAll(x => x == null);
foreach (GameObject go in EnemyArea)
{
go.SetActive(true);
}
}
My guess is when you exit play mode, OnDestroy runs, thus playerLand is null at that time since you aren’t in play mode at that point. You can always test this by doing a null check on playerLand. Debug.Log is also your friend.
You can add Debug.log calls to your Start method and your OnDestroy and spit out some values.