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
2
Question by Nirvana33 · Jul 28, 2013 at 12:15 AM · gameobjectlistexists

how to check if object already exists in a list

I have a list

List myList

i add a gameobject to my list

myList.Add(x);

i want to see if x gameobject is already in the list.

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
9

Answer by Lovrenc · Jul 28, 2013 at 12:20 AM

You have Contains function which tells you weather you have an element in the list or not. But hence, lists are not the best data collections if you dont want/need duplicates. They get slow pretty fast as you increase number of elements in them.

Comment
Add comment · Show 17 · 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 Nirvana33 · Jul 28, 2013 at 02:53 AM 0
Share

How to i can use it?

if(items.Contains==gameobject)

??

avatar image Chronos-L · Jul 28, 2013 at 03:19 AM 3
Share

Click the link and read the page and you will know that you should use if( items.Contains( gameObject ) )

avatar image Nirvana33 · Jul 28, 2013 at 06:51 PM 0
Share

how to check if same gameobject is attached?

avatar image nixcs2512 · Jul 28, 2013 at 09:36 PM 1
Share

@ByDream: what do you mean? you can simple check it before add it into List like:

 if(myList.Contains(x)) //if x is in list
 //Do nothing or something you want to
 else //if x isnt in list
 myList.Add(x); //Add x into list 

and Lovrenc is right,there are many documents about List, try to read and understand them first. But anyway, hope you can get the answer you want.

avatar image Nirvana33 · Jul 28, 2013 at 09:53 PM 0
Share

I understand this code. But i have a problem: Im created x gameobject 5 times. Then im attached one of the gameobjects. I want check if exists this 5 gameobjects. But its check only attached gameobject. Hope understand. Sorry for bad English..

Show more comments

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

21 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

Related Questions

A node in a childnode? 1 Answer

Get first gameobject in a list and cycle through on keypress 1 Answer

How to remove objects from a list ? 3 Answers

Ordering a list of GameObjects 3 Answers

Can't add GameObjects to ArrayList 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