- Home /
The question is answered, right answer was accepted
Text box and Image not appearing?
The text box and image i added thru the UI options in the hierarchy menu appear in the scene view but when I start the game and it switches to game view the text box and image box arent there. Im using them to display score and have tried changing their size, what could be causing this issue? And how can I fix it?
@SKY3E can you post a picture of your canvas and it’s transform? I’m betting that it’s screen space UI which is rendered differently to world space UI - it doesn’t have to be in front of the camera as it operates in screen space. It’s a little silly that unity show it in the 3D scene view at all tbh. Can confirm or deny this with information about the canvas and it’s transform. :)
For anyone wondering how I fixed it, in inspector, after clicking on canvas in Hierarchy, there is a setting called render mode. I used to have it set to "Screen Space - Overlay". I just changed that setting to "Screen Space - Camera" and it fixed my issue. Thanks to everyone who helped me fix my issue!
Might be worth noting that having your canvas as screen space overlay isn’t necessarily a problem or a bad thing, just that using camera space instead defaulted your content to a position that was in front of your camera. Glad it works now though! If you ever find that real world objects clip your UI then screen space overlay might be worth another look but I’m sure it’s fine for now :)
Here are the unity docs for reference: https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/UICanvas.html
Answer by Hawaii_Dev · Apr 07 at 11:50 AM
@SKY3E make sure that they don't get reset to "" in the text and null in the image when the game starts by the code controlling the score counter. Otherwise it might be a issue with the camera not rendering UI layers. Could you share the code that changes the score.
@Hawaii_Dev Here is my code :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ScoreScript : MonoBehaviour {
public Text scoreText;
public float scoreAmount;
public float scoreIncrease;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
scoreText.text = "Score: " + (int)scoreAmount;
scoreAmount += scoreIncrease * Time.deltaTime;
}
}
I dont think my code is the issue but it could be.
@Hawaii_Dev And btw, my image is just an image Ui with an edited color in unity, so nothing that i change through my code and it still doesnt appear.