I am having some problems with some code I have to spawn my player characters.
Specifically, this is a snippet of code that is checking which direction the player should be facing when they spawn.
if (CurrentLevelInfo.SpawnFacingLeft != null)
if (CurrentLevelInfo.SpawnFacingLeft.Length >= desiredSpawnPoint) {
if (CurrentLevelInfo.SpawnFacingLeft[desiredSpawnPoint])
bFlipThePlayer = true;
}
Now, most of the time I have no need nor desire to change what direction the player faces, so I have some code in there to make sure that the level info actually has this quality set. It is a simple array of bools, and it corresponds with the spawn points which is also set up in the same script.
But yet for some reason, it isn’t working. I have a line in there to check specifically if the array is long enough, but I still hit a null reference exception if the array doesn’t have any length. I even check is the array exists, but I still hit this exception when the length is zero. WTF? How am I supposed to check this without it stopping my code from executing?