I just installed Android logcat to debug my game from Unity's package manager. I don't fully understand how it works or in what order the logs are shown relative to my code.
The problem I have is that my game works perfectly fine without any errors on the Unity editor, but when testing it on my build, it doesn't work as expected.
When I used the Android Logcat to see what's wrong, it turns out that one of my code's functions does not fully execute (it stops halfway through), and at that point there is a NullReferenceException
error. But how do I identify the exact line of code the error comes from?
Here's a screenshot of my logcat:
EDIT: Here is the method that calls GameEnvironment.ObstacleSpawnPoints()
if (CurrentLevel().Equals(1) || levelData.Environment.ObstacleSpawnPoints().IsNullOrEmpty()) return;
int numberOfObstaclesToSpawn = levelData.Environment.ObstacleSpawnPoints().Length;
for (int i = 0; i < numberOfObstaclesToSpawn; i++)
{
int tagIndex = UnityEngine.Random.Range(0, levelData.Environment.ObstaclePoolTags().Length);
levelData.m_ObjectPooler.SpawnFromPool(levelData.Environment.ObstaclePoolTags()[tagIndex], levelData.Environment.ObstacleSpawnPoints()[i].position, Quaternion.identity);
}
This is GameEnvironment.ObstacleSpawnPoints()
public Transform[] ObstacleSpawnPoints()
{
if (properties.ObstacleSpawnPoints.Equals(null)) return null;
Transform[] spawnPoints = new Transform[properties.ObstacleSpawnPoints.childCount];
for (int i = 0; i < spawnPoints.Length; i++)
spawnPoints[i] = properties.ObstacleSpawnPoints.GetChild(i);
return spawnPoints;
}
GameEnvironment.ObstacleSpawnPoints()
method and where it's called, as we can usually diagnoseNullReferenceException
s based on that. \$\endgroup\$