• 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 /
  • Help Room /
avatar image
0
Question by unity_4XWcnhMEUZ043g · Jul 25, 2021 at 08:22 AM · uieditorscreenlayout

How to make child of layout group always fit the screen size and be placed side by side?

Hello, I have a next gameobject $$anonymous$$erarchy:

EDIT: Be aware: The screen is indicated by 4 arrows pointing at 4 corners of the 2 images I gonna post next.

Canvas :::: UI Scale Mode: Scale With Screen Size

    l
   Scroll View :::: Anchors: Stretch, Stretch , left:0 , right:0 , top:0, bottom: 0
            l
        Viewport :::: Anchors: Stretch, Stretch , left:0 , right:0 , top:0, bottom: 0
                  l
              Content :::: Anchors: Stretch, Stretch , left:0 , right:0 , top:0, bottom: 0


Content has: (beside 3 c$$anonymous$$lderns (Image components)) :

Horizontal layout group: C$$anonymous$$ld Alignment: Middle Center

Control C$$anonymous$$ld Size: Width (checked), Height(checked)

Use C$$anonymous$$ld Scale: Width (not checked), Height(not checked)

C$$anonymous$$ld Force Expand: Width (checked), Height(checked)

And i get t$$anonymous$$s result: alt text

Instead of t$$anonymous$$s:

`alt text

Why is a c$$anonymous$$ld fit to screen, instead of having the size of the screen and side to side to one another? How can I do t$$anonymous$$s?

EDIT: What I actually want to ac$$anonymous$$eve, is to have an array of gameobjects with an Image component, that is always having a screen size and be placed side by side to one another. And when I slide left or right on my screen, to move images left or right (that's why I put it in scroll view's content).

pic1.png (9.1 kB)
pic2.png (10.1 kB)
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 Hellium · Jul 27, 2021 at 01:36 PM 0
Share

Can't you set the anchor max of your Content object to (3,1) instead of (1,1)?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Levi_Visser · Feb 18, 2022 at 09:50 AM

I don't know if you're still looking for an answer to t$$anonymous$$s question, since it has been some time. But since a lot of people follow it, I thought lets answer with the solution I just found after working on t$$anonymous$$s for a couple of hours and t$$anonymous$$nking way way to difficult.

The solution is actually pretty simple. You have a scrollview with a horizontal layout group component and content size fitter on the content object.

alt text

I set it up like the image above. Then, on your content objects you add the following code

 using UnityEngine;
 
 namespace _Code {
     [ExecuteInEditMode]
     public class ForceUpdateRectToMainCanvas : MonoBehaviour {
         [SerializeField] private RectTransform mainCanvas;
         private RectTransform rectTransform;
 
         private void OnEnable()
         {
             UpdateRect();
         }
 
         private void OnRectTransformDimensionsChange()
         {
             UpdateRect();
         }
 
         private void UpdateRect()
         {
             rectTransform = GetComponent<RectTransform>();
             rectTransform.sizeDelta = new Vector2(mainCanvas.sizeDelta.x, mainCanvas.sizeDelta.y);
         }
     }
 }


T$$anonymous$$s sets the size delta of the c$$anonymous$$ld objects in your scroll view, to the size of your canvas. Also in Editor mode. And since the Horizontal layout group does not control c$$anonymous$$ld size, it just works! :)

Hope t$$anonymous$$s helps for anyone who might have t$$anonymous$$s issue now or in the future.


schermafbeelding-2022-02-18-104530.png (26.0 kB)
Comment
Add comment · Show 1 · 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
avatar image way2tushar · Dec 27, 2022 at 04:23 PM 0
Share

Cheers mate! It works great. Thanks

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

288 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 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 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 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 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 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 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 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 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 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 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 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

What's the background class of: Add Component window, Color Field window, Object Field window? 0 Answers

Unity editor - Keep columns narrow 0 Answers

How to set sorting order of UI elements, when Sorting Group doesn't work? 2 Answers

Canvas Error - Everything tinted blue 2 Answers

Scale unity 2020.1 UI EDITOR on linux Mint with XFCE desktop "INCREASE INTERFACE DPI" 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