Original Question: I’d like to know if a button that uses Sprite Swap, will mark the canvas as dirty when the user hovers the mouse over the button?
*Edit for clarity:
When certain parameters change in a canvas, it causes Unity to “rebuild” the mesh via Canvas.buildBatch. This is cpu intensive and can cause spikes/hiccups.
This article mentions only Transform changes as a cause of a rebuild:
The article goes so far as saying that changing text does NOT involve a batch build. My question seeks certainty regarding other types of changes such as a button sprite-swap on hover or the tint effect on hover. (Assume there are NO animations)
anything that changes the canvas will force a canvas repaint, not only images, scroll bars buttons animations, anything. thats why you should separate canvas depending on when their objects get dirty, if you have a button that is animated, it should go in a separate canvas from the static buttons.
According to Unity 2017 Game Optimization by Chris Dickinson, the only action which doesn’t dirty the canvas is changing the Color property of a UI element.
Hence I assume a color tint transition won’t rebuild the canvas, but a sprite swap will.
I keep asking myself the same initial question and when I Google, I find my own question as a top result, so here’s what resources I’ve found to help me through the whole Static vs Dynamic Canvas decisions:
.
A simple tutorial about correctly setting up the UI hierarchy of mixed Static and Dynamic parts of your UI:
.
A deeper tutorial explaining a 2-canvas setup and using the profiler to see the impact:
I’m new to game development, so blissfully unaware of that one sorry
You’ll need much smarter Devs to answer that one.
Not sure it’ll help, but there is a LateUpdate() function you can use to ensure what you are doing is at the end of the frame, if timing of a particular piece of code per frame is important.