Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Does changing UI image during runtime cost performance?

Discussion in 'Scripting' started by unity_To_IBocGqYHxwg, Jun 25, 2019.

  1. unity_To_IBocGqYHxwg

    unity_To_IBocGqYHxwg

    Joined:
    Jun 24, 2019
    Posts:
    5
    I am currently creating a content for oculus go that has several ui images in it and if user click a button it will change the images of the ui. I have imported DOtween plugin to do some animation for the canvas like fadein, fadeout and moving. I am expecting that dotween doesn't cost that much performance compare to unity animation.
    The problem I am having is when i click a button the application freeze like for milliseconds and my canvas animation fadein from half of the process. The alpha should star fading from 0.0f to 1.0f in 1.0seconds but it just freezes for milliseconds then start from like 0.4f to 1.0f.
    I want to achieve the fadein animation smoothly without freezing so I guess maybe changing the image does cost a little bit performance but thats just my assumption. What can I do to achieve smooth fadein animation?
    Thank you.
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    When you change image the new mesh and material are uploaded to video memory. But should not be noticeable since it happens very fast and there are only 2 to 18 triangles.You should check in profiler what is going on when you change the image before making any decisions. This may save you a lot of time.
     
  3. unity_To_IBocGqYHxwg

    unity_To_IBocGqYHxwg

    Joined:
    Jun 24, 2019
    Posts:
    5
    Hi pales-nx, thank you for your reply.
    I will try to check in profiler to see whether it's my code causing the problem.
     
  4. unity_To_IBocGqYHxwg

    unity_To_IBocGqYHxwg

    Joined:
    Jun 24, 2019
    Posts:
    5
    It seems like changing the sprite doesn't cause performance in my application. The main reason is the Canvas.SendWillRenderCanvases() takes like 345ms when I clicked a button that fades my canvases and move my canvases. I have read an article that said moving canvas around will trigger Canvas.SendWillRenderCanvases() because it needs to recalculate or something. Is there anyway I can try to improve it?
     
  5. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    Anytime you change anything in a canvas the entire canvas will rebuild. If you need to update certain items often you should sub canvas them.