Prefab does not scale in scale with screen size mode in UI
In unity 2d UI I have switched the canvas scaler into scale with screen size mode.
For those components added into the canvas manually the scaler works well. But for those added by scripts, even from the same prefab, the scaler does not work.
The appearance of the script-added component depends on the resolution setup, and mostly looks differently to those added manually, like following:
The first button is added manually and the rests are adde by scripts. I've set the button layout to be horizontally expanded so they should have fit the screen width but didn't. Anyone have ideas this could be a bug or did I set anything wrong?
Answer by IgorSimovic · Feb 11, 2016 at 11:00 PM
I have same issue until i set
go.transform.SetParent(parent.transform, false);
And now works fine
Thank you! Why this isn't covered in the Shop UI tutorial, I'll never know. If I had any reputation points to reward you, they'd be yours.
This is still working as the answer in 2017. You are the real $$anonymous$$VP!
Thanks! Still the solution in 2018.3.
For any other noobs out there, implementation looked like this for me: resultObj.transform.SetParent(resultsPanel.transform, false);
Where resultObj was the object scaling incorrectly and resultsPanel was the parent is was being added to.
Thank you so much! Been trying to figure out a weird bug for like one hour. Thanks again!
Your answer
