thisNpcScript.newScale = new Vector3(1.0f / dimension, 1.0f / dimension, thisNpcScript.transform.localScale.z);
All of the NPCs are 0.1 units thick, and 0.1 decimal is a non-terminating binary value. Reading the value out of the engine,
doing math on it, and plugging it back in requires some care. Over decent intervals of time, the error was building up, so
we got thick NPCs. It’s hardcoded now.
Using the test code I threw together, and a little tweak to give them all the same material, it’s easy to get a horde of
dudes wandering blindly north-ish through town.
I’m beginning to suspect that nothing before the SetActive(true) is actually happening, or at least isn’t having
a real effect. Let’s check that theory.
tempNpc.gameObject.SetActive(true);
if (recycledNpc) print("Recycled NPC has ID " + tempNpc.npcId + " when it should be " + npc.worldNpcID);
if (tempNpc.npcId != npc.worldNpcID) Debug.Break();
No good, it always has the right ID. But some further playing saw my PC being inactive at the gameObject level. How could
that be happening?
if (npcScripts.ContainsKey(npc.worldNpcID)) {
tempNpc = npcScripts[npc.worldNpcID];
if (!tempNpc.gameObject.activeInHierarchy) {
print("NPC " + npc.worldNpcID + " not active!");
Debug.Break();
}
Well, that triggers a bunch if we cycle through some gangs of dudes. So we’re pulling references out of the npcScripts
dictionary even if they’ve been thrown back in the recycler. I think we can fix that.
if (npc.lastActiveRound < maxGameRound - 10) {
NpcScript tempNpcScript;
if (npcScripts.TryGetValue(npc.worldNpcID, out tempNpcScript)) {
tempNpcScript.gameObject.SetActive(false);
}
npcScripts.Remove(npc.worldNpcID); // oops, forgot to do this
npcLocations.Remove(npc.worldNpcID);
if (npc.isPC) activePcs.Remove(npc.worldNpcID);
} else {
and now everything works as it should. I’m beginning to look forward to rewriting most of this code with what I’ve learned,
but that will have to wait.