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 jcfrizz · May 07, 2018 at 02:07 AM · buttonslistsscrollviewpanelobject pool

Deleting button when item removed from list?

Hi everyone, currently I am trying to change the list of buttons that show in a scrollview when certain conditions occur. I am doing this by creating two lists, and items created with an Object Pool switch between two lists. The items are created into ui buttons during runtime. Right now, the items transfer between the two lists perfectly fine, and the buttons are created fine. The issue is, my buttons aren't removing, and I don't know why. I have the function running in Start() and Update() so that it is running constantly. Also, in this code, I am trying to remove the button from the homePanel. So how do I remove the buttons that are equal to the specific item I am referring to? Here is my code:

 public void hideUnmatchingDates(Item item)
     {
         for (int i = homePanel.itemList.Count - 1; i >= 0; i--) {
             if (homePanel.itemList [i].dateButtonAdded.ToString () != logDate.text) 
             {
                 hiddenPanel.itemList.Add (homePanel.itemList [i]);
 
                 GameObject newButton = buttonObjectPool.GetObject ();
                 newButton.transform.SetParent (hiddenPanel.contentPanel);
                 ActivityBookButton activityButton = newButton.GetComponent<ActivityBookButton> ();
                 activityButton.Setup (homePanel.itemList [i], hiddenPanel);
 
                 homePanel.itemList.RemoveAt (i);
 
                 //button not removing with these lines for some reason
                 GameObject toRemove = transform.GetChild (i).gameObject;
                 buttonObjectPool.ReturnObject (toRemove);
 
                 Debug.Log ("item transfered to hidden panel");
             }
         }
     }
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
Best Answer

Answer by KittenSnipes · May 07, 2018 at 04:24 AM

@jcfrizz So I know it is removing from the list and there is nothing wrong with your code. So I think the only solution is figuring out what you are trying to grab. So based on the call the object the script is attached to is where you are grabbing the child object for removal. So what is the parent object and what is the child? If you know what you want to remove then that will be your solution. If you need more help feel free to comment.

 public void hideUnmatchingDates(Item item)
     {
         for (int i = homePanel.itemList.Count - 1; i >= 0; i--)
         {
             if (homePanel.itemList[i].dateButtonAdded.ToString() != logDate.text)
             {
                 hiddenPanel.itemList.Add(homePanel.itemList[i]);
 
                 GameObject newButton = buttonObjectPool.GetObject();
                 newButton.transform.SetParent(hiddenPanel.contentPanel);
                 ActivityBookButton activityButton = newButton.GetComponent<ActivityBookButton>();
                 activityButton.Setup(homePanel.itemList[i], hiddenPanel);
 
                 //Should remove it from list
                 homePanel.itemList.Remove(homePanel.itemList[i]);
 
                 //What transform is this attached to? 
                 //button not removing with these lines for some reason
                 GameObject toRemove = transform.GetChild(i).gameObject;
                 buttonObjectPool.ReturnObject(toRemove);
 
                 Debug.Log("item transfered to hidden panel");
             }
         }
     }
Comment
Add comment · Show 2 · 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 jcfrizz · May 07, 2018 at 03:51 PM 0
Share

The parent is a game object that I call the content panel (in my code the two content panels are the "hiddenPanel" and "homePanel") which is what the script is attached to. The child is the button that is created in this content panel. In this area of the code, I am trying to remove a button (child) from the homePanel (parent). This button (child) is created with the information given by the item selected in the itemList. Does that make sense? It's sort of difficult to explain super well. Also, the content panel is the child of a scrollview viewport, so in the game, the buttons appear in a scrollable list for the user to be able to see.

But yeah I guess my issue is that I don't know how to get to in my code what it is that I'm trying to grab, and then how to delete it.

avatar image jcfrizz · May 07, 2018 at 04:16 PM 0
Share

I actually figured it out!! Ins$$anonymous$$d of using the line

 GameObject toRemove = transform.GetChild(i).gameObject;

I used ins$$anonymous$$d:

 GameObject toRemove = homePanel.contentPanel.transform.GetChild(i).gameObject;

I think the issue was that I wasn't specifying what the transform was, which you pointed out. So once I said what the tranform was in my code, it worked!

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

83 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

Related Questions

What is the best way to handle a scenario game with a LOT of panels? 0 Answers

Looking for help with Scrolling List / rows for tv UI ( via game controller) 0 Answers

Assign images to list of buttons 0 Answers

Putting Dictionary/List using foreach as buttons in a scroll view? 3 Answers

UI Button : Previously working but now it's not working 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