- Home /
High CPU usage in UIPanel.LateUpdate of NGUI
Hi all,
Recently I'm testing my game on iPod2 device. My game's UI solution is NGUI. I found that UIPanel.LateUpdate alwasy cost about 7ms - 10ms every frame. I think this is abnormal, does anyone know what's going on about the high cpu usage in UIPanel.LateUpdate?
Thanks.
Answer by whydoidoit · May 08, 2013 at 11:24 AM
Yeah it's rebuilding one of the atlas materials every frame. This is not a good thing.
I'm struggling to remember why I had that - I think it is one panel with two atlases or something.
Right $$anonymous$$e was due to it thinking things had moved when that wasn't really true!
I changed UINode to do the other way of testing for rebuild and it's fine now:
/ /---------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2012 Tasharen Entertainment //----------------------------------------------
#if UNITY_3_4 || UNITY_3_5
#define UNITY_3
#endif
using UnityEngine;
using System.Collections.Generic;
/// <summary>
/// UIPanel creates one of these records for each child transform under it.
/// This makes it possible to watch for transform changes, and if something does
/// change -- rebuild the buffer as necessary.
/// </summary>
public class UINode
{
int mVisibleFlag = -1;
public Transform trans; // $$anonymous$$anaged transform
public UIWidget widget; // Widget on this transform, if any
public bool lastActive = false; // Last active state
public Vector3 lastPos; // Last local position, used to see if it has changed
public Quaternion lastRot; // Last local rotation
public Vector3 lastScale; // Last local scale
GameObject mGo;
public int changeFlag = -1; // -1 = not checked, 0 = not changed, 1 = changed
/// <summary>
/// -1 = not initialized, 0 = not visible, 1 = visible.
/// </summary>
public int visibleFlag
{
get
{
return (widget != null) ? widget.visibleFlag : mVisibleFlag;
}
set
{
if (widget != null) widget.visibleFlag = value;
else mVisibleFlag = value;
}
}
/// <summary>
/// $$anonymous$$ust always have a transform.
/// </summary>
public UINode (Transform t)
{
trans = t;
lastPos = trans.localPosition;
lastRot = trans.localRotation;
lastScale = trans.localScale;
mGo = t.gameObject;
}
/// <summary>
/// Check to see if the local transform has changed since the last time this function was called.
/// </summary>
public bool HasChanged ()
{
bool isActive = NGUITools.GetActive(mGo) && (widget == null || (widget.enabled && widget.color.a > 0.001f));
if (lastActive != isActive || (isActive &&
(lastPos != trans.localPosition ||
lastRot != trans.localRotation ||
lastScale != trans.localScale)))
{
lastActive = isActive;
lastPos = trans.localPosition;
lastRot = trans.localRotation;
lastScale = trans.localScale;
return true;
}
return false;
}
}
Answer by DuckOfDoom · May 08, 2013 at 11:39 AM
As you can see UIPanel runs over all transforms on LateUpdate() to see if their geometry has changed and updates matrices and clipping bounds. So CPU usage like this is pretty standart. You can adress this as optimization request to NGUI creator at Tasharen.com.
Your answer
![](https://koobas.hobune.stream/wayback/20220613101825im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
NGUI Implemeting Date Picker 0 Answers
Positioning Label with NGUI 1 Answer
loading assetbundle from assets folder 0 Answers