0
\$\begingroup\$

I am working with a 2D game, in Unity. I am able to see the texture, in the Unity editor, but after taking the desktop build the texture is not visible to the scene.

What could be the problem?

\$\endgroup\$
  • 1
    \$\begingroup\$ I had something similar happen recently on a project where multiple user accounts were editing assets in a shared folder. The OS file system decided to give one user exclusive permissions to some files. They still displayed fine in the Unity editor (presumably it was using the Library's cached assets generated by the owner user), but when a build was generated by the second user the assets would be missing. Resetting permissions on all files in the project fixed it. Can you check the problem textures/materials to see if their permissions look odd? \$\endgroup\$ – DMGregory Oct 7 '16 at 15:38
  • \$\begingroup\$ @Gnemlock: it solved a problem with similar symptoms for me, but it sounds like it was not a solution to the asker's problem. As you noted, there are a lot of possible explanations for these symptoms. \$\endgroup\$ – DMGregory Jan 24 '17 at 0:48
1
\$\begingroup\$

You say 'I am able to see the texture in the editor' - you do not say 'in the editor, I can see the texture when I run the game'.

While it is difficult to diagnose the exact problem, based off your provided description, it is important to remember that in a build, we will only see our game as it appears in the game view. In contrast, there are many situations where an element would be visible to the editor view, but not visible to the game view.


Ensuring the texture is visible to the game view ensures that the texture should be visible in a build. If you can not see it in the game build, this could help further diagnose the problem. This seems to be confirmed, through comments.

Its a the problem with my camera view – user1509674 Oct 7 '16 at 10:40


There are a couple of ways in which a camera may be set up to limit the display of the texture.

Position

If an object is not within your camera's field of view, it will not be rendered to the screen. It should be obvious that the texture needs to be in front of the camera, but there are other variables that effect whether the texture will be rendered, based off it's position relative to the camera.

  • Clipping plane: The camera's clipping plane determines both the closest and furthest distances to which the camera will render. Anything before the local Near distance or after the local Far distance does not get rendered by the camera. The camera has a gizmo to let you drag these distances in and out, via the inspector. It should be noted that a negative Near distance will allow you to include objects behind the camera, if this should ever be useful.

"As an example, if the camera is at position (0, 0, -10), and looks at an object at position (0, 0, 0), it will need a Far greater than 10 and a Near less than 10; as the object is 10 units away.

  • Size / Field of View: An orthographic camera will have a size, while a perspective camera will have a field of view. These values effectively do the same thing; they determine the size of the camera's view. In the case of perspective cameras, the camera's view becomes an angle; the further away you get, the wider the view. As such, the closer an object gets to the camera, the closer it needs to be to the cameras center view for it to be rendered.

A perspective camera views outwards at an angle. This has an effect on the display of objects.

Texture Rotation

It is important to note the rotation of the object containing your texture. Ideally, you want your texture to be facing the camera. Since a texture is 2D, it does not have a Z depth; if you face it away from the camera, at a 90 degree angle, it simply will not be visible.

The texture shrinks as the facing angle reaches 90 degrees, and eventually disappears.

Culling Mask

Lastly, it is possible that the camera is being told to cull the layer containing the texture. There are many reasons you may want to actually do this, but it is important to remember that a culled layer will not be rendered to that camera. Under the SpriteRenderer attached to your texture object, you will find a Sorting Layer. Ensure that this value is checked, on the camera, under CullingMask. Alternatively, ensure that the camera has it's CullingMask set to Everything.

Make sure that the camera has the same layer checked as the SpriteRenderer's Sorting Layer. Alternativley, ensure the camera has "Everything" checked. By default, a texture will use a Sorting Layer of "Default".

\$\endgroup\$
1
\$\begingroup\$

As Gnemlock points out in a comment above, even though in this specific case the problem seems to have been due to the camera being misaligned for viewing the texture, this question may attract hits from people with other problems leading to these symptoms:

  • The textures appear normal when viewing scenes in the editor.
  • Textures are missing or show black/magenta default appearance when running a compiled build of the game.

So, here are a couple of things you can try to troubleshoot these types of problems:

  1. Close Unity, delete your Library folder, then re-open Unity.

    Unity keeps a cache of pre-processed assets in this folder, and occasionally they can become corrupted, leading to strange behaviour. All of your source assets are in your Assets folder, so deleting Library won't lose any of your work - it just forces Unity to do a full re-import on its next run, giving you a clean asset cache to work from.

  2. Close Unity, reset file permissions on all files in your project, then re-open Unity.

    As mentioned in my comment above:

    I had something similar happen recently on a project where multiple user accounts were editing assets in a shared folder. The OS file system decided to give one user exclusive permissions to some files. They still displayed fine in the Unity editor (presumably it was using the Library's cached assets generated by the owner user), but when a build was generated by the second user the assets would be missing. Resetting permissions on all files in the project fixed it. Can you check the problem textures/materials to see if their permissions look odd?

\$\endgroup\$
0
\$\begingroup\$

If you drew something which contains transparency, the transparency might be the problem.


I had a similar issue, using Tiled. The scene was fine with transparent tiles on upper layers. However, my app did not manage the transparency correctly, and the lower layers was invisible on screen.

\$\endgroup\$
  • \$\begingroup\$ Its a the problem with my camera view \$\endgroup\$ – user1509674 Oct 7 '16 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.