I have a procedural round box that I want to use for the texture on the widget. The widget will be able to scramble and I want the shader to adjust to the size of the widget.
How do I get the size of the widget through the editor shader?
Hm, you can’t get it (afaik) but you can pipe the data in through a parameter. You’d need to create a Dynamic Material Instance with a parameter and update the material when the widget changes size. You may need to call Force Layout Prepass just after updating widget size but before getting Desired Size to ensure you’re not fetching stale data.
I’m assuming you need more from this than just a border that autoscales as there’s a much better solution to this that fiddling with a material. Leaving a link just in case - Setting Image States:
The fact is that I will have a huge number of widgets(1000+) and there will not be 3D graphics.
I wanted to minimize the number of components in the widget that would unload the CPU.
In this case 9-slice would about 1000 x performant than a widget with a material… (eyeballing it!)
You do not need to add any new components, it’s just a clever way to stretch a plain image.
Hi I think what yu try to achieve can be done with the box/border style setting of an image.
documentation
I’ll just add a tip, perhaps it will save you some time. If you decide to use the styles, design the smallest border you need and use that. Otherwise scaling down may compromise quality.
If the smallest you’ll ever get is 32x16, for example - design a 16x16 border. Also, the margins are percentages. So margin of .1 means 10% of the actual size - so for a 32x32 border, the margin of 10% would be 3 pixels.
Good luck with the rest.
I know this is an older question, and perhaps, this is a more recent Unreal addition, but it looks “Pixel Size” on GetUserInterfaceUV will return the size of the current widget being rendered.