- Home /
non-sprite GameObjects in 2d games
I'm using a lot of particle effects and text mesh objects in my 2d game, and laying them out in the editor is incredibly awkward, because they will always appear behind any sprites in the scene (one of which is the BG image and covers the whole scene).
I'm able to bring them to the correct layer in-game with a script like this on each of them:
var sortingLayerName : String;
var sortingOrder : int;
function Start () {
var someRenderer : Renderer = this.renderer;
someRenderer.sortingLayerName = sortingLayerName;
someRenderer.sortingOrder = sortingOrder;
}
but this doesn't affect what i can see in the editor.
Are there any workarounds for this? Or is it something that needs to be fixed in unity? (quite urgently in my opinion!)
Thanks for any help.
Answer by Dblfstr · Mar 04, 2014 at 02:53 PM
This seems obvious, so forgive me if you have tried this. Bur if you are working in 2D mode (working in the X-Y plane). Try adjusting your objects location in the Z direction. Because when you add object to your scene, often times the Z location is seemingly random, so you objects could literally be behind your sprites. I keep all of my 2D stuff at certain Z coordinates depending on what they are supposed to do. I also like to use increments of 5. So my normal stuff is all a Z=0; but intermediate background is at Z= -5, and background is at z= -10, Buttons and stuff are at Z = 5, or Z = 10, depending on their function. You can easily adjust this buy changing to 3D mode to situate your gameobjects.
Yes, tried that! Thanks though.
The z location doesn't seem to do anything in this situation, maybe it is somehow overidden by the sprite sorting layers system
Figured. But I do not use rendering layers. I use physics layers, for collisions. I control my rendering via the Z axis. So I am not sure how render layers will affect the outcome.
So i should just not use the sorting layers at all? Is it possible to do this with sprites, and just have the z deter$$anonymous$$e order?
Do you have multiple cameras? This can affect what is shown as well. I do sometimes keep a camera for GUI stuff and a camera for the game stuff. Have to make sure to check the camera depth and culling to display everything properly.
for anyone else's future reference - just put all sprites onto the "default" sorting layer in order to use the z position to deter$$anonymous$$e order ins$$anonymous$$d