0
\$\begingroup\$

so I have two sprites, a box and an X animation (I'm making Tic-Tac-Toe). So, in the code, when I click on the box, it instantiates the X animation at the right place. The X animation does not have a background, but the box does. However, when it instantiates, it puts it behind the box.

This doesn't make sense to me, but even when I move it around in the editor, moving it across the box puts it behind it. Which is interesting, since neither have layers. And even when I do put layers on (a higher layer on the X animation), it still goes behind. Take a look:

Disappearing GameObject

Any ideas on why this is happening, and how I can fix it?

EDIT: Here's my hierarchy and inspector:

Hierarchy and Inspector

\$\endgroup\$
3
  • \$\begingroup\$ Can you post the screenshot of your components and heirarchy? \$\endgroup\$ May 17, 2018 at 14:33
  • \$\begingroup\$ Higher Sorting Layer or Order in Layer? Do they have the same depth (Z coordinate)? \$\endgroup\$
    – wondra
    May 17, 2018 at 14:57
  • \$\begingroup\$ @wondra Yep, they both have the same layer (though even if the X animation is higher, it's still behind), and the Z coordinate for both is 0 (and when changed for the X animation, it stays behind). \$\endgroup\$
    – CyanCoding
    May 17, 2018 at 16:26

2 Answers 2

1
\$\begingroup\$

Though I'm not sure why, I tried messing around, and putting the Z-radius of the X Animation behind the box, it actually showed up in front of it (with the Z-radius of the X animation being -2 and the box being 0).

\$\endgroup\$
1
  • \$\begingroup\$ Since the default camera looks along the positive z axis, smaller / more negative numbers are actually closer to the camera. So -2 is in front of 0..You can verify this by putting your scene view into 3D mode and looking at your content from the side. \$\endgroup\$
    – DMGregory
    Apr 25, 2019 at 2:14
0
\$\begingroup\$

From your edit, it looks like you’ve selected the X animation GameObject. I see that it’s on the Default sorting layer. See SpriteRenderer component’s layer. If you have multiple layers, put the X animation on the a foreground layer. You can create new layers if you don’t have any.

If you are not able to create/use a different layer due to some reason, you can change the Order in Layer property of the SpriteRenderer component. It is currently set to 0. You can try changing it to 1 or more.

Putting the X animation slightly closer towards the camera, meaning a slight negative offset than the box, will also work. But remember, if you move the X animation in z axis, and you’re using a perspective camera, the result might not be what you are looking for. I would prefer doing it in either of the 2 above mentioned ways

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .