Search Unity

[uGUI 4.6 Beta] Slow when update Text from script.

Discussion in 'Immediate Mode GUI (IMGUI)' started by KaOzz, Sep 9, 2014.

  1. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    Hi there,

    When I add a Text in the new uGUI, with a Dynamic font, or the default Arial, and I update that text with something like this:

    Code (CSharp):
    1. ...
    2. using UnityEngine.UI;
    3. ...
    4. public Text myText;
    5. ...
    6. void Update()
    7. {
    8.       myText.text = Time.time.ToString();
    9. }
    The game slow down on Android (4.4.4, Nexus 10).

    If I disable the Text component, the game run smoothly.
     
    Last edited: Sep 10, 2014
  2. Kogar

    Kogar

    Joined:
    Jun 27, 2013
    Posts:
    80
    weird. Have you tried it with the old gui? Does it also slow down?

    Small optimisation: I don't think there is a need to update a text 60 times a second or even more (depending on the max framerate) Here is shown how to call a function with a reduced update frequency. http://answers.unity3d.com/questions/237816/updates-refresh-interval-and-how-to-change.html

    btw. what minimum android api have you set in your preferences?. I just tried 2.3.1, 3.2 and 4.4 and haven't seen a noticeable slowdown in a short test on an Android 4.4.4 device
    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.EventSystems;
    4. using System.Collections;
    5.  
    6. public class test : MonoBehaviour, IPointerDownHandler {
    7.    public Text  myText;
    8.    public bool updateTime=false;
    9.  
    10.    void Start () {
    11.      myText = GetComponent<Text>();
    12.    }
    13.  
    14.    void Update () {
    15.      if(updateTime)
    16.        myText.text = ""+Time.time;
    17.    }
    18.  
    19.    public void OnPointerDown(PointerEventData eventData)
    20.    {
    21.      updateTime = !updateTime;
    22.    }
    23. }
     
  3. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    HI Kogan,

    With texts (GUIText) on the old gui I had the same issue. I was waiting for the new uGUI to see if it fix it.

    Good point, I also changed Update function to FixedUpdate, and also tried with a custom function called with InvokeRepeating every 0.5 seconds. Also had set targetFrameRate to 60. Same result.

    Im using Minimum API Level at 2.3.1. Tested 4.4 also. Same result.

    Scene:
    Fresh project with only one Text object (uGUI), and just one cube rotating with transform.Rotate.

    Tested on Nexus 10, Andriod 4.4.4 and Samsung Galaxy S3 Mini, Android 2.3.1.
     
    Last edited: Sep 10, 2014
  4. KaOzz

    KaOzz

    Joined:
    Oct 15, 2012
    Posts:
    82
    Last edited: Sep 10, 2014