- Home /
Why is my sprite not rendering when it is clearly on screen?
I have a sprite onscreen, but it is not rendering. Here's some relevant data:
sprite.renderer.enabled == true //Good. The renderer is not turned off.
sprite.gameObject.active == true //Good. The renderer's game object is not turned off.
Camera.main.active == true //Good, and obvious since it's rendering other stuff
GeometryUtility.TestPlanesAABB(
GeometryUtility.CalculateFrustumPlanes(Camera.main),
sprite.renderer.bounds) == true //Good. The sprite is within the frustum of the camera.
Camera.main.cullingMask & sprite.gameObject.layer == 0 //Good. The sprite is not on a layer that is culled by the camera.
sprite.renderer.isVisible == false //VERY BAD AND WRONG. Why would it not be visible?
As far as I can tell, the only things that would affect isVisible are the renderer's bounds, the camera's frustum, the sprite's layer and the camera's culling mask. As seen, all of those values indicate that it should be visible. What else might cause isVisible to be false?
Note that this only happens sometimes. Other times it is perfectly visible. It appears to be related to what else is on the screen when it is instantiated. There are two scenes. When on scene A and it's instantiated, it shows up and continues to display when transitioning to scene B (because of DontDestroyOnLoad). When on scene B, it's invisible, even after transitioning to scene A.
For more information, I've also collected some other data that I don't believe is relevant, but I've included here anyway:
sprite.renderer.material.color == (1,1,1,1) //Good
((SpriteRenderer)sprite.renderer).color == (1,1,1,1) //Good
sprite.transform.scale == (1,1,1) //Good
Camera.main.orthographic == true //Good
Edit
I've discovered that one way to cause it to not disappear as often is to disable reflection. Obviously this is not a tenable solution. I'm using a modified version of the Unity-provided water reflection script/shader. It seems like a bug in Unity at this point. I'm not currently running the latest version of Unity (I'm on 4.5.5f1), but I didn't see anything in the release notes of 4.5.5f2+ to indicate it's fixed, and I can't easily upgrade.
Edit 2
This does not happen in the editor. It only happens on a device (iOS).
also try peaking into build settings and tweaking the rendering path between the values, take a look at the Unity Rendering Path manual as well :/ hope it helps
I'm just curious about: what is the reason why you did not update Unity yet to the last 4.6?
$$anonymous$$any reasons we haven't updated yet, including being very close to shipping and we don't want to introduce any new bugs.
Answer by MrSoad · Dec 08, 2014 at 09:32 PM
This could be a Z(Depth) drawing issue. It may be that some of your objects shaders are set to draw over the sprite shader. Try a different Shader on the Water as a test to see if this removes the issue. If so your modified shader may need editing.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173540im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3D Objects are not being in their regular shape at distance 2 Answers
Frustum culling doubt 2 Answers
Image effects do not work when rendering with multiple cameras 0 Answers
How to render objects outside the camera's view? 1 Answer
occlusion culling conflict with shader,Occlusion culling conflict with shader 0 Answers