Author Topic: UISprites in world space/UIPanel performance  (Read 2329 times)

jrhee

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 13
    • View Profile
UISprites in world space/UIPanel performance
« on: April 15, 2014, 12:35:54 PM »
Hello,

I'm trying to create UISprites in world space underneath my characters (flat on the ground). The approach I've been able to get working after some reading on the forum is basically:

CharacterObject
- UIPanel
-- UISprite

Just wanted to confirm- is this the best approach to accomplish this? I'm a little concerned about performance, since I'd need to create a UIPanel for every character on screen. Would it be possible (better?) to use a single UIPanel and update the sprite positions to the characters'?

Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprites in world space/UIPanel performance
« Reply #1 on: April 16, 2014, 10:11:27 AM »
Yes, it's the correct way to go. If the characters are moving, you will get better performance by using several panels rather than one. Moving panels is efficient. Moving widgets within the panel is not.

ikkiChia

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UISprites in world space/UIPanel performance
« Reply #2 on: July 21, 2014, 03:00:34 AM »
Hi,

I have a question. Currently I designing a game where there will be many units moving around. As each unit is created, an UI object, which consists of a UILabel and 2 UIProgressBar, will be created. The 'UI Object' will follow the unit in the 3D environment by using Raycasting.

The hierarchy is as follow :

unit
unit
unit
UIRoot
-UICamera
-UI Object
--UILabel (for Name display)
--UIProgressBar (for Health bar)
---UISprite (Background)
---UISprite (Foreground)
--UIProgressBar (for Armor bar)
---UISprite (Background)
---UISprite (Foreground)
-UI Object
--...
-UI Object
--...

According to the Draw call tool, there is 1 draw call with 10 widgets.

Assuming I have 3 units with 3 'UI Object' being created. Whenever I moved the camera or a unit moved, the performance dropped (According to the Profiler, UIPanel.lateupdate() will 39.2% and 3 ms, majority goes to WriteToBuffer in UIPanel.FillDrawCall and UpdateWidget in UIPanel) rather significantly. The game which I am currently designing will consists of more than just 3 units (approximately 30 to 50, and most likely at least half of units or the UI Camera will always be moving), so may I kindly ask for some opinion in the improvement in the performance?

Note : On my side of the code, I already implemented that there will not a updating of the UI Object's transform position if current position (After Raycasting) is the same as the previous.
« Last Edit: July 21, 2014, 03:17:30 AM by ikkiChia »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UISprites in world space/UIPanel performance
« Reply #3 on: July 21, 2014, 05:07:20 PM »
There is absolutely no reason to perform a raycast. Use transform.OverlayPosition to change the UI Object's position to overlay a 3D object, or -- if you have HUDText -- attach UIFollowTarget to it.

That said, performance will still go down when you do this because you're moving widgets around. Moving widgets is expensive as buffers need to be rebuilt. If you want to speed this up, attach a UIPanel to your UI Object so that you'll be moving a panel around. Moving panels is cheap.