One of the more perplexing bugs I encountered working on Novantica so far was when all the NPC extras in the game suddenly turned a greenish-yellow color. I had just swapped out URP materials for ones using a new shader, so I suspected that change made this happen, but I didn't want to revert back to the old materials. To add icing to the cake, this issue was only happening in builds, not in the editor. I started to dig in, but didn't realize it would take so long to track down.
At first, since I didn't know how to reproduce the issue in the editor, I tried swapping different materials and shaders on one of the character models to see if it was related to any prefabs used to spawn the extras. No luck, the character was still yellow. After a bit of fruitless searching on the Unity forums, I tried moving the model to different scenes and sometimes the material worked and other times not. I also noticed that the NPCs that were loaded from additive scenes didn't suffer the same ailment, as seen in the screenshot above. Those scenes were Addressables, so I started to suspect it was something related to how I'd set up shared materials across scenes with the Addressables system.
I switched the Unity Addressables Play Mode Script option to Use Existing Build and was able to start reproducing the issue in the editor. It felt like I was onto something.
The next thing I tried was adding all the game's materials and textures to a new Addressables group. This seemed to fix the yellow people problem, but now the materials were missing from some of the additively loaded Addressable scenes. If you're familiar with Unity, the magenta colored objects in the screenshot above mean that the materials are missing. I tried a few different ways of grouping the materials in Addressables, but still wasn't able to get everything working as expected.
At this point, I went outside to take a walk and clear my head. Why were the characters turning yellow? They should be rendering in magenta if the material was missing. The shader looked like it was supposed to but only the color was off...
Then it dawned on me. When I got back to the computer, I swapped the texture on the character material to confirm my suspicion. The material was, in fact, working, but the UV maps were wrong. But why?
This time, I found some useful hints from the forums. It turns out the default Optimize Mesh Data setting on the imported character models was causing the UV map to get lost somewhere along the way. As you can see in the texture above, the UV map controls how the low poly models are colored. For some reason, the UV map was only set for one of these colors.
After disabling this on all the imported FBX models, everything was rendering as expected again. Case closed.
If you've run into similar issues with Unity, I hope this post was helpful, but if you know of another or better way to avoid this issue, please let me know.
Alternative titles considered for this post:
- What is up with all these wasabi people?
- Perplexed by the pea soup people
- The curious case of caper colored characters