Rezise model to match canvas

I am trying to create a room with framed pictures on the wall, I have a model from blender that I have placed as a child under a ui canvas object. I already have code to set the image in the canvas based on a public variable, what I want to be able to do is make the frame model match the size of the parent canvas.

The idea being that I can save this as a prefab then recreate it with different image sources so that no matter what size image I use and its dimensions the 3d model will match it.

I’m not sure how to do this or if I should be using something other than ui.frame for this.

The answer I eventually came up with was I manually lined up the frame with the canvas, then in the code:

  • Load image source dynamically from url variable.
  • Get the pixel size of the image.
  • Resize the canvas to the image pixel size.
  • Work out the percentage difference in the height and width of the image from the original default size.
  • Apply this percentage difference to the scale attribute of the frame model.

Worked perfectly :slight_smile: