1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. Unity 2017.1 beta is now available for download.
    Dismiss Notice
  5. Unity 5.6 is now released.
    Dismiss Notice
  6. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  8. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Static Flag not working on UI Elements?

Discussion in 'Unity UI & TextMesh Pro' started by lorddevil, May 16, 2017.

  1. lorddevil

    lorddevil

    Joined:
    Jul 21, 2015
    Posts:
    17
    Hey there,

    I am using solely the UI objects below a canvas for a TCG. When changing their attributes to "Static - Everyone" or using the StaticBatchingUtlity.Combine feature - nothing happens. Like this gets totally ignored on objects below a canvas?

    I can also freely move those static flagged objects around and I can also see no change in batching/drawcalls etc. - as far as I know the recttransform should get fixed once the object is static?

    So is the static feature not available for UI objects?

    Oh and why do I need this?

    For performance reasons I want that if e.g. 40 cards are laying down on the "floor" they don't need to get processed all the time (each card uses several layers of objects with alpha transparency and they are high detail - so this is GPU.renderoverlay intense). I thought there must be a way so I can tell the UI those objects are not "disabled" - but don't need to get rerendered all the time?

    Thanks in advance,
    Oliver
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    2,444
    The unity UI is based on a batching System that batches all elements that use the same materials / Same textures together.
    It does not use / need the static flag.
    You may enable the sprite packer to pack your textures into atlases to reduce the needed draw-call count.
    https://docs.unity3d.com/Manual/SpritePacker.html
    Unless you backe the ui element into a texture they will be rendered every frame they are on screen. The most expensive part is rebuilding the ui mesh in case something changed. So if they are not moved is souls be kind of cheep.

    If you can backe your multi layer card into one texture at runtime this could work too.
     
  3. lorddevil

    lorddevil

    Joined:
    Jul 21, 2015
    Posts:
    17
    Hey there and thanks for the reponse...

    yeah I did a lot of testing the last days and was able to see exactly what you are describing. On PC or modern phones this usually isn't much of an issue, but experimenting with older devices (android 5-6) it is.

    So I am now going a different route. I build a cardgenerator scene - where I render all my cards via RenderTexture to an image folder - which then I put into an assetbundle. This way the cards are only 1 images again and the textmeshpro parts I render over it - since I need dynamic text. This works pretty good performance vice.

    However I still see a FPS drop when dragging the cards once 40+ cards are layed out. Even though they are 1000x1500 pixels large - because you can always tip on them to show them full screen to see all details - I am mainly only using them scaled down to 0.15f - so maybe 150x225 pixels are visible. But it appears to me that internally it is still using the full res 1000x1500 image - causing an issue on those devices. Because when I change the images to 512 in size - the FPS raises from 45 to 60 again. I thought when not changing the scaling property it only renders the current scale - doesn't seem like ??

    So I have 2 more ways of improvements now. Using 2 images and replacing them once I make one card full screen - this would surely work well. And I could use 2 canvas... one for the lying cards and one for the dragging card. So dragging a card would not affect rendering on the other cards. Especially since Unity always needs to process every card once I move one within the canvas - this may give a great performance boost?

    What do you think?
     
  4. lorddevil

    lorddevil

    Joined:
    Jul 21, 2015
    Posts:
    17
    So I guess for now I am done... I have full 60 fps on 45 cards layed out, all using the original 1000x1500 background. What I do now is just using a reduced texture for the mobile device which only uses 600x900 as its base - because its all about the texture size it cares not the scale - so beware if using a high res image at a low scale....
    Also I am using now 2 canvas - so if I select one card it moves it to the foreground canvas and then back to the backgroundcanvas - this way even while dragging I can maintain the 60fps on a Samsung Tab A. Now I need to get an even older device to check how it behaves there :)