- Home /
Disappearing world space text after setting its text value
Hi, I have identified my problem and looking for a workaround, if anyone knows. What happens is that as soon as I set the text value of a world space text, the text disappears. The value is there properly and can be seen in the editor, but is invisible in the game view.
I have a world space canvas that constantly looks at the camera, that contains some game bars and a title that pulses (scales up and down constantly). It works great as an announcement board for my game. Now I wanted to add some simple floating texts for things like + score, + health etc.
I am using a text prefab with a script that has a coroutine for making the text move up the Y axis slowly. This is the coroutine that shows that I first change the text, then start the coroutine for making the text fly upwards.
private IEnumerator ShowAssistObjectResults(float energy)
{
floatingTexts[0].SetText("Energy",energy);
floatingTexts[0].PlayFloatText();
yield return new WaitForSeconds(breakTime);
}
This is my SetText method:
public void SetText(string text, float value)
{
floatingText.text = value > 0 ? text+ " + " + value : text + myValue;
floatingText.color = value > 0 ? positiveColor : negativeColor;
}
And finally the FloatText Coroutine:
public void PlayFloatText()
{
StartCoroutine(FloatAndDisable());
}
IEnumerator FloatAndDisable()
{
t = 0f;
while (t < flyDuration)
{
t += Time.deltaTime;
y = _rectTransform.anchoredPosition3D.y;
_rectTransform.anchoredPosition3D = new Vector3(x,y + floatingSpeed*t ,z);
yield return null;
}
_rectTransform.anchoredPosition3D = startPosition;
floatingText.text = "";
}
I have tried setting the text to random values in the code (e.g. "test" ) and the floating text works as intended. For some specific reason, using the one line ifs I have above or passing another value makes the text go invisible. I am using Unity 2018.3.0f2.
I suspect it has something to do with setting the text to be "dirty" even though I am not really familiar with the definition of that.
maybe text borders is too small to show your long text? It may explain why it worked fine with small texts like random numbers and "test" text
Nope, tried editing that in the editor and it showed the text without problem
Hmm... How about color? Is there a chance that during setting color it is set to be transparent?
Answer by centralinfo · Jun 13, 2019 at 11:38 AM
Hi,
Try setting the Sorting Layer drop down box on the canvas, as well as the Layer drop down at the top of the inspector. This will set the sorting layer for your game objects.
Chris
Your answer
Follow this Question
Related Questions
Heya, does anyone know how to make WorldSpace canvas Text less blurry/pixelated 2 Answers
Canvas UI Priority layers 1 Answer
World space buttons and preventing UI touch passthrough 0 Answers
3rd party UI - World Canvas or Screen Space Camera? 0 Answers
World Space Canvas not rendering in front of Overlay Canvas 0 Answers