Why is my sprite invisible when infront of the background layers?
I've been trying to make the first level of my game, and I've run into a problem where my sprite completely disappear from the scene whenever it's in front of the background layers I've implemented but appears just fine when said layers are turned off. I made my character sprite using Photoshop and added bones to it via the unity sprite editor. I've tried adjusting the order of the layers but so far nothing works. I'm completely stuck.
Here are some screenshots (with background and without background)
Any solutions? Thanks for reading.
Answer by streeetwalker · Mar 13, 2020 at 05:27 PM
You're background layers are in front of the player. Check the sort layer and sorting value in the Renderer component on each object, and also the transform z value. Smaller z values are closer to the camera for objects in the same sorting layer at the same sort order value.
I already tried adjusting the z-axis, but the character just disappears from the background regardless of its position. I even experimented using 3D mode and that came to no avail.
Note how my character is standing in front of the background but disappears when both layers overlap.
@Gabarial, We have to see the rendering component inspector for both objects to be able to tell what is going on.
In my experience with sprite objects, z axis value only has an affect if objects are in the same sorting layer and also the same sort order number.
So if the sort layer is background and the sort order is 1 for both objects, then z=0 for one and z=1 for the other will make the z=0 object appear in front.
Here is what you should do if you're not already, just to prove you can get the player in front:
1. create two sorting layers, 'background' and 'player'. $$anonymous$$ake sure the player sorting layer is at the bottom of the sorting layers list. This is opposite to how photoshop works where layers at the top are visually on top. (I guess Unity's logic is that layers at the bottom are drawn last and therefore appear in front?)
2. assign the player layer to the player and the background layer to the background in the Render Component's Sorting Layer drop down menu.
Now tell us that does not work!
Look over this documentation carefully: https://docs.unity3d.com/$$anonymous$$anual/2DSorting.html
Answer by Gabarial · Mar 14, 2020 at 02:46 PM
It worked, thank you so much! It took some effort, but after fiddling with the sorting layer I was able to manage it. Let me know if you need help with something, so I can pay you back
Your answer
Follow this Question
Related Questions
How to place my own UI Image? 1 Answer
My graphics of the game pixelated on High Resolution Graphics 0 Answers
UI Button Doesn't Render [C#] 0 Answers
UI image component problems with Character Creation.... 0 Answers
Hello :) I'm trying to detect gaze input on a sprite image. How to do it? 0 Answers