Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • 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 hierarchy:

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 childerns (Image components)) :

Horizontal layout group: Child Alignment: Middle Center

Control Child Size: Width (checked), Height(checked)

Use Child Scale: Width (not checked), Height(not checked)

Child Force Expand: Width (checked), Height(checked)

And i get this result: alt text

Instead of this:

`alt text

Why is a child fit to screen, instead of having the size of the screen and side to side to one another? How can I do this?

EDIT: What I actually want to achieve, 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
0

Answer by Levi_Visser · Feb 18 at 09:50 AM

I don't know if you're still looking for an answer to this 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 this for a couple of hours and thinking 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);
         }
     }
 }


This sets the size delta of the child objects in your scroll view, to the size of your canvas. Also in Editor mode. And since the Horizontal layout group does not control child size, it just works! :)

Hope this helps for anyone who might have this issue now or in the future.


schermafbeelding-2022-02-18-104530.png (26.0 kB)
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

287 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

Related Questions

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

How can I detect when the name of a gameobject has been changed in the editor and do something when that happens? 2 Answers

Is there anyway to make an input field stretch to fit a body of text? 0 Answers

remove value from LayoutElement.preferredWidth by script 1 Answer

New GUI - Order of elements? 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