Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Drexster · Mar 20, 2012 at 03:23 AM · arrayslistsiterate

iterate through array of objects with lists of objects

I need to iterate through an array of objects, each of these objects holds multiple generic Lists of objects. The purpose is to compare a specific object with the contents of the generic lists and to remove it from the 1 list it exists in (it really only does exist in 1 list).

The problem is, when i try to remove the object from the list in question, it removes each object of the same type (by Tag) from each array object's list, and not just the "one".

Each object in the arrColum has a script called Check, which contains multiple generic lists of objects.

This is the script is use to iterate through my array of objects with Lists:

 var arrColum = new Transform[8];
 function RemoveFromColum(theObject : GameObject)
 
 {
 for (var colum : Transform in arrColum)
         {
             
             if(colum != null && colum.gameObject.active ==true)
                 {    
                     var checkScript : Check = colum.gameObject.GetComponent(Check);
                 
                 if(theObject.transform.tag == "Cube")
                     {
                         var theCubeList : List.<GameObject> = checkScript.cubeList;
                         RemoveFromList(theCubeList, theObject, colum.gameObject);    
                     }        
                 }
         }
 
 }
 
 function RemoveFromList (theList : List.<GameObject>, theObject : GameObject, theColum : GameObject)
 {
     var index : int = -1;
     var checkScript : Check = theColum.GetComponent(Check);
     for (var curr : GameObject in theList)
         {
             ++index;
             if (curr.transform.GetInstanceID() == theObject.transform.GetInstanceID())
             break;
         }
     if( index >= 0 && index < theList.Count)
         {
             theList.RemoveAt(index);
             checkScript.columCount-=1;    
         }
 }

Can anyone point out what I'm doing wrong here. Or suggest a better/quicker way of achieving this properly?

Comment
Add comment · Show 3
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 Owen-Reynolds · Mar 20, 2012 at 02:51 PM 0
Share

Don't see anything obviously wrong -- add a bunch of Debug: "start remove" "remFromList#2", "remObjID45672", "doneRem". I'm wondering maybe if someone else isn't just calling this for lots of objects.

As far as the structure, depending on what you are doing: if every item can be in only one list, you could have the objects responsible for knowing who owns them.

avatar image Drexster · Mar 20, 2012 at 07:43 PM 0
Share

That's exactly what i ended up doing. Creating a breadcrumb system that i could query to see which array object "owned" the object in question and then only iterate through the appropriate List in that said owner object.

Still perplexing why it would remove multiple objects even after using GetInstanceID to compare to make sure only the one was removed. I'm not sold on GetInstanceID consistently providing a truly unique ID...

avatar image Owen-Reynolds · Mar 20, 2012 at 10:58 PM 0
Share

Print out each list, using InstanceIDs, just before a remove.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multidimensional Array of Vector2 2 Answers

Display text on gameobject via user inputs 1 Answer

How to store aspects (position, name, tag) of a game object in an array to be used for reinstantiation? 1 Answer

Converting JS Array to Generic List 2 Answers

Making a list of obect's parents their parents from one script. 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