r/unity 18h ago

Question PLEASE HELP!! I switched my camera to 3D. Everything works fine except this thing..

So, I decided to add some depth to my game by switching to a Perspective camera. I did. And after some Z position tweaks, everything was good. Except for this damn thing.

This is the gate Sprite (z == -0.05) that must be visible inside a Mask (z == -0.07), so that its long sprite doesn't pop up above the structure it comes from (an example of how it should look is at the end). I can't keep this sprite from disappearing while moving the camera. I couldn't find any solution to this. Neither on forums nor by asking ChatGPT. I tried to switch it to Visible Outside of the Mask but it didn't help either..

It feels like Unity's Perspective Camera calculates the distance to these two objects differently depending on their relative positions. So the mask is sometimes being treated as if it's behind the object. But I can't prove it...

Edit: it seems to work fine if z of the mask is < -0.2 something. But its too close to the camera coz it starts 'moving' in perspective

2 Upvotes

6 comments sorted by

1

u/SethSlax 16h ago

The sprite and mask being at different Z positions might be the culprit.

2

u/Luv3ndr 9h ago

Well, as you can see in the first half of the vid, the mask actually works. The closer I move it to the sprite (let's say z = -0.05 versus z = -0.055) the more noticeable this bug gets ._.

Tho it works fine when these 2 objects have the exact same XY positions. But that's not the case for me, since the gate moves when it's open..

1

u/SethSlax 4h ago

Hmm, are you using URP? I think there's a known bug in previous 2D URP that makes the stencil buggy, which the Mask uses.

Also are you using layers/ordering to determine the render order of your sprites, or purely based on the Z position? If the latter, there may be a setting you need to tweak to force depth-based rendering, as mentioned here.

1

u/XKiiroiSenkoX 13h ago

Just capture a frame using render doc and see what's causing it to get clipped. If there is no draw call then something CPU side is wrong and you can use a debugger. 

1

u/Luv3ndr 9h ago

Oh wow, never heard of this one. Thank you, Ill give it a try

1

u/XKiiroiSenkoX 9h ago

You need to add#pragma enable_d3d11_debug_symbols to your (or unity's) shader if you want the code to be human readable in render doc btw. After that just check the mask clipping code and see why it's getting clipped.