- Home /
Prefabs for my UI look great in editor, but when played on android they are teeny tiny.
I've made a database management game in Unity and I'm releasing it on the google play store soon, but I'm stumped on a few prefabs not scaling properly. I have a few prefabs for things in the UI that will be a list. Like a list of games, or a list of players in those games. They need to be dynamic, and each needs to have a special action listener, so I used prefabs. These prefabs work perfectly other than not scaling right. In my Unity editor they fill the screen and look great, but when I run the game on an android emulator the prefab buttons become extremely tiny. I've tried attaching canvas scaling elements to them, and I set their anchors to the edge of the screen, but that doesn't seem to work. Do you guys have any tips for me figuring this out?
Edit: Added images, the first view is in the editor, the second view is from my android emulator
in the editor, in the game view, you can choose a resolution that simulates your phones resolution, even create new ones.
choose one that matches your phone and see if the ui still looks right in the editor.
Answer by deanpackard · Dec 16, 2018 at 04:57 PM
After continuing my research I found someone that had a similar issue many years ago, here is the answer post for that. https://answers.unity.com/questions/1037474/prefab-does-not-scale-in-scale-with-screen-size-mo.html To summarize this already short answer, where I'm instantiating my prefabs and setting their parent container like so
go.transform.SetParent(this.transform);
I have to actually set an overloaded value, worldPositionStays, to false like so
go.transform.SetParent(this.transform, false);
after doing this my UI works perfectly. World position stays, when true, makes it so when your parent container changes, your prefab remains the same, which we don't want. so just set that to false and WALAH!
Answer by CentauriDev · Dec 16, 2018 at 08:32 AM
Have you set the canvas to scale with screen size?
This scales the ui elements with the screen
Yes, I have done this. I have them in a scroll view and vertical layout group. I think the issue is in there. Here are screenshots of the settings in the layout group and for the prefab
It is strange, because when I set the canvas to scale with the screensize, everything did except my prefabs
Your answer
Follow this Question
Related Questions
GridLayout Scaling Issues 1 Answer
Multiplayer UI scaling 0 Answers
Scale UI with distance 1 Answer
How to I scale UI 9-slicing across different resolutions? 2 Answers
Associate UI with gameobject 2 Answers