• 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
2
Question by Smileys · Jan 14, 2015 at 04:47 PM · user interface

UI Instantiation - Layout Group does not work

Hi, i have several layout groups in my UI. The layout groups that are populated at runtime (Instantiate Buttons) work just fine. However the layout groups that are setup in Editor dont work at runtime. All Layout elements are clumped at one spot and i have to manually dis- and then enable the Component or Gameobject. I tried to do this with scripting but with no success. My GUI GameObject looks like this:

GUI_Go ->Canvas ->->Panel ->->->Empty_with_LayoutGroup ->->->->Buttons

Is there any workaround or solution to this problem? Thanks in advance.

Comment
Add comment · Show 2
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 Guy-Corbett · Sep 13, 2015 at 02:03 PM 0
Share

Hi there,

Did you come up with a solution for this? I've run into a similar problem and I've not got a fix but I may have a work around. It seems my hierarchy contains two scroll rects above the layoutgroup. I know that seems like bad practice buy it makes sense in my case. Anyway I found that my layout group worked fine if I disabled the second of the two scroll rects (the one further down the hierarchy).

I tried changing my script to disable that scroll rect before it instantiates the contents of the layout group and then re-enables it after. That made it work fine. Just to double check I tried taking that disable and re-enabled code out again, so that my code was identical to how it was before, and it continued to work perfectly.

I've definitely not made any other changes, I checked with my source control program. It seems the unity editor had got into a funny state and was confused by my nested scroll rects. I intend to leave in the code that enables and re-enables the one scroll rect, as nasty as that it is, just so that it will automatically right it'self should this happen again. Still it would be nice to know what was going here.

avatar image Guy-Corbett Guy-Corbett · Sep 13, 2015 at 11:11 AM 0
Share

Just a quick note, I realized that though I had reverted all my code changes I hadn't reverted all my changes to the editor - the layout group only continued to work for because the scroll rect was still disabled in the inspector. Opps.

In short, in order to get my layout group to correctly set the size of objects I instantiate at run time, I'm having to always disable one of my two scroll rects before I instantiate, and then re-enable it after.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Hypellosh · Oct 07, 2015 at 05:56 PM

As Guy Corbett has said above, if the layout group is within the content object of a scroll rect, instantiated objects will lose their connection on a value change (in my case a position change of its parent object).

"Simply" do ScrollRectObject.GetComponent<ScrollRect>().enabled = false; before the value change and ScrollRectObject.GetComponent<ScrollRect>().enabled = true; afterwards.

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.

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

27 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

Related Questions

UI System for Non-minimal User Interfaces 0 Answers

UI element following mouse when using "Scale With Screen Size" 2 Answers

Universal Method of finding pixel dimensions of UI elements 1 Answer

Set InputField non-interactable without clearing text 1 Answer

Slider and Input Field Value Updates 1 Answer


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