Shader and normal map working when editing, but sprite turns black when running with animations

Hi all, so I have a strange issue that only starts happening with animated sprites and only when the game is running or built, NOT during editing. I have a character sprite with a shader and a normal map that appears to work fine in the scene view AND the game window while I’m editing. You can see the character and the trees working correctly in this screenshot, both using the same shader in separate materials with their corresponding normal map:


Note: I pulled the trees randomly online to test with because the character wasn’t working. In case you recognize them as someone else’s trees.

I can move a point light all around the sprite during editing and light is mapping correctly, including every animation (during editing by playing each animation from the Animation window).

Once I run the game it becomes a 100% black silhouette, but only for the player:

It seems to only be going black for an animated sprite and only if the animation changes, as it stops turning black when I disable the animation script, thereby allowing it to stay on the default animation. The animation script doesn’t control anything directly, it only updates parameters like “Grounded” and “Speed” so the Animator can choose the transitions.

How do I make sure each animation continues to use the normal map? Or is that not the problem and there’s something else I should be fixing?

The shader I’m using: http://6502b.com/article.aspx?id=67

Any insight would be greatly appreciated! Thanks in advance!

When entering playmode is your player gameobject set to a position which is infront of the light? Try fiddling with things in the inspector while this problem is showing, that can help a lot when debugging this stuff.

I found the problem! I was setting my localScale on the object with a Vector2. Everything is working if I remove this line from my animation script:

transform.localScale = new Vector2(thePlayer.lastDirectionPushed, transform.localScale.y);

And replace it with this:

transform.localScale = new Vector3(thePlayer.lastDirectionPushed, transform.localScale.y, 1f);

I’m not sure why I would have had a Vector2 for my localScale in the first place, but all is well now!