I’ve built a game that runs fine in the editor. But once I play it in build (developer mode on), exceptions pop up.
By reading the output_log.txt in xxx_Data, I have tracked down the problem to my Dictionary for pool manager. I was putting pools into a pool manager for easy reference later.
The code looks something like this on the Pool
.
[SerializeField]
String _name;
void Awake() {
Debug.Log("Name: "+_name);
PoolManager.AddPool(_name, this);
}
The _name
is a unique identifier for the pool. For example, “Projectiles”, “Debris” etc. Now here comes the fun part.
In the editor, the console displays:
Name: Debris
UnityEngine.Debug:Log(Object)
Name: Projectiles
UnityEngine.Debug:Log(Object)
In other words, absolutely no problem.
But in my build, the file logs the following:
...
UnloadTime: 0.349474 ms
Name: [SOH] // <------------------------ HERE!!!!
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Vst.Performance.PoolBase:Awake()
...
[SOH] is an ASCII character. Like [NUL] and other non-displayable characters. You’ll know if you’ve used Notepad++ before.
So my build is actually, using [SOH] as a key to the Dictionary. What follows are catastrophic. When my Projectiles pool gets added, because Debris is already inside the dictionary with key [SOH], I first get ArgumentException
, saying the key already exists.
Later, when my weapons start instantiating projectiles from the pool, I get TONS and TONS of KeyNotFoundException
because the pool couldn’t be added in the first place.
Since the Awake
and Start
of said objects are cut off midstream due to exceptions, they fail to instantiate properly, leading to TONS and TONS of NullReferenceException
when the Update
loop starts to run.
So can anyone tell me WHY this is happening to me?
A million thanks.
Vst.