Unity2d: Why does this sprite act like it is behind the background even though its Z-value is set to be in front of the canvas? - unity3d

Showing the general setup of the scene and where the sprite is
the sprite is "behind" the background but the Z-value should be correct
I have tried solutions such as changing the render mode of the canvas; the different options do not work and "World Space" turns the game view into the default background color. I could not figure this out after a day of reading up manuals/guides and looking at other questions. Thank you for helping me!

The issue is you are trying to use a SpriteRenderer on a Canvas object. Remove the SpriteRenderer and either use an Image or RawImage component instead.
Another note regarding UI that you will inevitably run into is unless specified otherwise, objects further down in a Canvas hierarchy will render on top of those above it.
I would also avoid changing the z-axis on all of your objects. Make Canvas groups that have different sorting layers to render groups on top of one another. Place objects in a specific order in the hierarchy to get the draw order you desire. Messing with the z-axis in a 2D scene can be a headache down the line and is not very modular. If you want to change sort order later, the specific z offset you set to each object will need to change.

Related

How to create a a gameobjective that is only visible in scene view, not game

I would like to create a bunch of gameobjects to be used as spawn points and path finding targets, I’d like these to be visible on the scene view, even while the game is running, but not visible in the game. Seems like this should be a thing, but I’m failing to find it.
I’ve tried googling this, but all I find are people that are experiencing this behavior, but it undesired.
If you just want to see them, you can use OnDrawGizmos.
Inside this MonoBehaviour function, you can use Gizmos.DrawSphere(position, radius) to draw a sphere that can only appear in scene view. You just need to use the position of your GameObject as the position argument and you can draw as many spheres as you want. There are other shapes as well, see what fits your needs better.
Read the documentation for an example. Make sure to have your Gizmos activated in the scene mode, otherwise it doesn't appear.

How to bring forward an object in unity?

I've a simple project with a few objects.
I tried to move "player" object (Marked in the picture) to top of other objects but still it is in backward!
How to bring it to forward?
We need some more information to give an accurate answer for your exact situation, such as the properties of the Sprite Renderer (assuming Player is a sprite) and the properties of your Canvas and UI elements (especially if it is a world space canvas), and any code you might be using to instantiate, render, or move the player.
In general though, for sprites, you can bring a sprite in front of other sprites by either changing the Z value of the transform (negative Z is closer to the camera), or better by changing the Order in Layer of the player sprite renderer, and make sure it is in a layer that is in front of the other sprites.
As for Canvas UI elements, the element at the bottom of the hierarchy will be rendered last, meaning it will show in front of everything. Think of a UI hierarchy like stacking papers on top of each other. The first piece of paper placed down will be at the bottom of the pile.

How to make one game object to be in front of another in unity

I heard that game objects are drawn in the same order they appear in the Hierarchy. But in my case it doesn't work.
For example I wanted the wolf is placed in front of the rabbit, but it doesn't work.
Is there some way to make it with sorting objects according in hierarchy or I can make it only with layers?
The hierarchy sorting you speak of only works in the canvas - so for example with RectTransforms and Images. However I guess you want to use Sprites. SpriteRenderer component has a Order in layer property. Plus Sprites are more lightweight than Images with Transparency. Or you could just move Transforms closer and further away from the camera (even if your game is 2D/ using an orthogonal camera). If everything fails you could change the RenderQueue of the Materials.

Recommendations for clipping an entire scene in Unity

I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).
Thus far I've got clipping working as I want for the terrain and a water effect:
The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.
Here's a pic showing the terrain clipping in the editor.
You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table.
The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.
While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.
Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?
The end goal is to render a scene within the bounds of some plane.
One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.
You can also use Bounds.Contains.

How to zoom out a material in Unity?

Ok, new to skyboxes here but Im having a problem involving a radial gradient material I'm using as a skybox and the field of view on my camera. My problem is this: the gradient looks great and ou can see the gradient part only when the camera's field of view is really high.
I built my whole scene at field of view 7 and at that proximity, I don't get a gradient here is the comparison:
I have my whole scene (the objects) in an empty, but even if I up their z value at the high field of view they don't look like they used to. Without completely rebuilding EVERYTHING in my scene position wise, how can I zoom out my material as the skybox?
Is there a way to up the field of view without moving away from the objects in my scene?
I can post my shader code as well.
Is there a way to up the field of view without moving away from the objects in my scene?
Here's the key: Because FOV basically zooms in you'll get all the ugly artefacts associated with being eye-ball close with something, such as your skybox. So, unfortunately the answer is no, you need to position your camera further away and increase the scale of your objects. To compensate just scale up all the objects in your scene, preferably in your 3D modelling app rather than in Unity.