I wonder why are all MaskableGraphic derived types (e.g: Text, Image, RawImage) maskable by default ?
This has certain performance implications (e.g: clipping for the object should be recalculated, etc).
Also, this option is not serialized, so you cannot control it from the inspector, instead you have to create a script that is added (additional overhead) to every object that you wish to turn masking off for.
Finally, suppose you create such a script - it may not execute fast enough to reverse the process that executes on all maskable objects, so you have to set it to execute early or any other “magic” hacks.
So, my questions are:
Why is masking turned on by default for all objects? the equivalent would be something like Object.GetHashCode() slowing down execution, even if the object is not placed in a HashTable.
Why can’t this be controlled from the inspector (e.g: serialized) ?
What are the exact requirements to trigger the clipping recalculations? I added a couple of Images into a canvas, disabled and re-enabled them and it didn’t do it.
I have seen some performance problems caused by MaskableGraphics in our company’s project, but I can’t access it right now.
EDIT: I’ll try it again later today. It was a quick test and I might have forgotten something from the scene.
@mikael_juhala i am not sure what are all the scenarios, but it looks like clipping calculations are triggered in these scenarios (found by looking at the UI code):
For MaskableGraphic derived types:
OnEnable
OnDisable
OnValidate (editor only)
OnTransformParentChanged
OnCanvasHierarchyChanged
For RectMask2D:
OnEnable
OnDisable
OnValidate (editor only)
For our use cases, these are enough scenarios to make me worry about performance. We use a single canvas for most of our windows, and we constantly enable / disable new UI components as well as re-parent them around.
I think this is already possible - the Unity UI code comes as a UPM package, simply include it into your project and modify what is needed to support this.