- Home /
Images added to Grid Layout during runtime not Resizing with Screen Size
I am working on a UI feature to show selected object images in a grid layout towards the bottom of the screen.
I have a canvas set to Screen Space - Overlay. This game object also includes a Canvas Scaler set to Scale with Screen Size and a reference resolution.
As a subset of this canvas, I have a Rect Transform with a Grid Layout Group and Content Size Fitter. During the game, I want to add one or more images to fit inside this grid layout.
This currently works great if the game is maximized at fill resolution, but if not, the images I add are larger than the cells they are supposed to fit into. Any suggestions would be appreciated please.
Answer by borasko34 · Jan 12, 2017 at 12:09 PM
I was having this same issue and what worked for me was the following. The objects that I was adding to the Grid Layout during runtime were prefabs that already had a script attached to them. So in the Start() section of the script I just added:
this.transform.localScale = Vector3.one;