- Home /
I need my GameObject to Spawn in front of my sprites
Hey guys,
I've been having issues spawning things into my game for awhile. However, I've almost got them spawning in perfectly and I just need a little help!
My game is spawning in an object that is basically just a button, and when it spawns in, it is behind all of the sprites on my Canvas. I had to change the Sorting Layer for the sprites earlier, because spawning the object in was causing them to all disappear, but now I can't get my new spawned object to spawn in front of those sprites!
I've tried dragging the new object around in my Canvas hierarchy, and that hasn't fixed it, and I've tried altering my Z value. I've also tried changing the Object Layer as well, and nothing. I tried to see if I could apply a sorting layer to my new objects, but it doesn't look like buttons have that option. Can anyone suggest anything that might work?
Thanks
Answer by darkmoosen · Apr 21, 2018 at 04:50 PM
I was able to come up with an answer for my own question after playing around with everything a little bit. I created two canvases, one for the Foreground Buttons and one for the Background Images. I placed all of my buttons in the Foreground Canvas, and all of my Sprites in the Background Canvas. After that, I was able to apply Sorting Layers to the Canvases themselves, and was able to put the Background Canvas behind the Foreground Canvas! Hope that helps anyone having the same problem!
Answer by Cornelis-de-Jager · Apr 19, 2018 at 10:24 PM
Have a look at this answer:
https://answers.unity.com/questions/1042298/how-do-i-move-a-game-object-in-front-of-another-on.html
I've tried sorting layers, and that helps with my sprites, but not my buttons/UI Elements that I'm bringing into my game. The sprites show up fine, it's the Buttons that are stuck behind the sprites. I even tried adding a Sprite Renderer to my Button so I could move it on a different sorting layer and that didn't fix the issue as well.