Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 patasana_7 · Sep 21, 2017 at 02:48 PM · instantiategridlayoutgrouparrange

dynamically re-arranging gameobjects in grid layout group

Hi everyone,

I have a panel(dropAreaHolder) which has a scrollable panel(dropArea) as a child. In my game I instantiate game objects by drag and drops and put them inside my scrollable panel (dropArea) (just like the idea in Scratch, cloning code blocks and putting them in a coding area). My coding area can only show about 20 code blocks. When the number of code blocks is larger than 20, then my scrollbar will become visible and player can scroll and see everything. When the number of code blocks become 20 or less, scrollbar is hidden again and scroll rect component is disabled. Up to this point everything works just perfect. But the problem is that when i remove lets say the first code block, the code blocks do not re-arrange themselves so i can't see all 20 code blocks, the last one always remains at the bottom - out of the masked area.

It looks something like that: alt text

screenshoot.jpg (54.2 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xgg · Oct 15, 2017 at 09:39 PM

I have a problem somewhat like this and would like to know if you found a way to update the GridLayoutGroup.

My problem is when I SetActive(true) an object in the GridLayoutGroup(glg), glg does not update the positions, so the object does not align with the others like it is meant to...

I found a hotfix, which is the:

 glg.gameObject.SetActive(false);
 glg.gameObject.SetActive(true);

It somehow sets off a process which works for me.

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 patasana_7 · Oct 17, 2017 at 08:00 PM 0
Share

Actually I kinda found a solution to my problem. Firs I made some arrangements in my script which is attached to my code blocks.

public void OnEndDrag(PointerEventData eventData) {

    //checking if code block is removed from my coding area 

     if(parentToReturnTo == null)
     {
         if (Scene$$anonymous$$anager.GetActiveScene().buildIndex == 3)
         {
             //Sending index of the removed code block to activitycontroller scipt in the active scene
             actController.reArrangeCodeBlocks(this.transform.GetSiblingIndex());
         }
     }
  }


And in my activitycontroller script in the active scene i create a function to rearrange code blocks in the drop area:

public void reArrangeCodeBlocks(int removedCodeIndex) {

     if (dropArea.transform.childCount == 19)
     {
         // changing index of the next code block
         GameObject nextCodeBlock = dropArea.transform.GetChild(removedCodeIndex + 1).gameObject;

         nextCodeBlock.transform.SetSiblingIndex(removedCodeIndex);
     }
 }




This solved my problem, I dont know if its the best solution to practice but changing the next code block's index automatically triggered the layout group to rearrange remaining ones for me.

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

87 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

Related Questions

Create placeholders in grid layout group? 1 Answer

Add Item to GridLayoutGroup using Instantiate 3 Answers

UI Layout Moves after you save or touch it in the Editor 0 Answers

Adding Imperfections? 1 Answer

Creating an Object with a string C#! How? 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