- Home /
Game slows down when printing text
Hi there,
I have implemented the dialog system from this Brackeys video in my project. Everything works perfectly, but when I have done the build for android I have seen that when printing texts that are too long, the game starts to slow down. The code divides the sentence to be displayed in the UI into an array of characters and then prints each character one by one, with a small delay. I have been doing several tests and first I thought that the problem was the coroutine from where the characters were printed. But then I have removed the code from the coroutine and I have seen that the more characters it prints, the more the game slows down.
void FixedUpdate()
{
if(typeSentence)
{
if(t <= 0)
{
TypeChar();
t = charDelay;
}
t -= Time.fixedDeltaTime;
}
}
private void TypeChar()
{
GUIs[dialogue.UIIndex].dialogueText.text += charSentence[sentenceIndex];
sentenceIndex++;
if (sentenceIndex >= charSentence.Length)
{
typeSentence = false;
sentenceIndex = 0;
GUIs[dialogue.UIIndex].continueButton.SetActive(true);
}
}
I don't know if there is a more efficient way to do it, or if someone can explain to me what is happening and why it slows down so much.
Can you run the inspector? You could see exactly what part of the code is slow
Answer by lvskiprof · Jan 21 at 10:21 PM
Is there some reason you are doing this in FixedUpdate() instead of Update()?
I am thinking that the issue here might be where you are doing it.
Update is called once per frame, so it will be called more times or less times depending on the frame rate but FixedUpdate is called always the same amount of times, independently of the frame rate. Thats the reason I use FixedUpdate instead of Update. So I think there is not the problem. As said before I used to do this on a coroutine and the problem was the same.