Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Redwolve · Jan 13, 2015 at 09:14 PM · uigridlayoutguilayoutwidth

Layout Element Issue

Alright, after a failed attempt to find a similar issue on here, I have returned with another query.

I am creating a memory match game, I wanted it to be very flexible (able to choose how many cards before building the grid and then building the appropriate grid), however some of the finer elements to keep it looking nice are failing me.

So here is how I am formatting my Grid:

I first have Canvas.

Then on the Canvas and PreRuntime I have a Panel that takes up the entire canvas.

At Runtime I Insantiate (in a for loop) a panel for the first row.

In another for loop, I Instantiate the Buttons that are my Cards.

This runs until, at the moment anyway, a 4X4 grid of cards is produced.

The panels and buttons are all Prefabs

The Main Panel has a Vertical Layout Group, ideally to keep all of the panels the same size, that part works. My panels are always equally sized.

The Prefab Panels are outfitted with a Horizontal Layout Group, ideally to do the same thing with the Buttons.

Each Prefab Button is outfitted with their own Layout Element, the Preferred Width set to .25.

At Runtime I set all of the images to Preserve Aspect, with them enable they strech across the entire cell, however they are still at random widths vice the Preferred Width setting of .25.

However, This only works for the Buttons if I have all the same size sprites on each of the buttons. I am trying to have the buttons have animal images of varying size and my thoughts were that with a preferred width would set each cell on the Panel to 25% and then scale the image to fit in the cell. this does not work at all, my smaller images have a thinner cell, and my larger images have a wider cell.

If I set all of their Preferred Widths to 1250 they all look proper on the aspect ratio I've chosen. I can easily go in and script them to be screen width /4 but i shouldnt have to do it that way, in my opinion.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Redwolve · Jan 13, 2015 at 11:00 PM 0
Share

I have tried removing all of the Child Force Expands for all panels and does not fix the problem either.

Running out of things to try.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Redwolve · Jan 14, 2015 at 04:30 AM

Well I have settled for the script run Preferred Height = Sreen Width /columns

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

25 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Add Item to GridLayoutGroup using Instantiate 3 Answers

Snap guides for laying out objects 2 Answers

Increase height of panel w/ gridlayout when new objects added 1 Answer

UI Vertical Layout Group with Content Size Fitter, how to set max width? 1 Answer

Determining if Horizontal Layout Group has room for an element. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges