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 Thomas · Nov 09, 2009 at 05:50 PM · arrayfindgameobjectswithtag

How to access the return value of GameObject.FindGameObjectsWithTag() ?

The Documentation says the function returns a "list" of GameObjects without saying if this means they are returned as a collection or array, but both accessing methods don't work:

var places = GameObject.FindGameObjectsWithTag ("place"); 
var i = Random.Range(0,places.length); 
myRandomPlace = places[i]; 
// nor: myRandomPlace = places.item(i);

The Debug window says the return type of the function is a GameObject itself, do I have to traverse it?

Comment
Add comment · Show 1
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 Ehren · Nov 10, 2009 at 03:49 PM 0
Share

Hi $$anonymous$$. You might want to rewrite your question to remove the inaccuracies (i.e. that places[i] doesn't work). Some people might not even know to try places[i], so it's still a useful question.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by abdullah.ahmed · Nov 09, 2009 at 06:39 PM

From the documentation it looks to be just a generic array of game objects.

You'd have to traverse it using a for loop in order to find the specific object you are looking for.

Check out the following article which details the different types of collections available in JS and C# for Unity 3d. Unity Coding: Arrays, Hashtables and Dictionaries explained

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
avatar image
0

Answer by Thomas · Nov 09, 2009 at 08:52 PM

I've solved my problem, it was actually not this part of the script but a later GetComponent("ScriptName") Call, which returned Null and raised a NullReferenceExpection. I thought it happened when I assigned the GameObject to the variable, but it didn't. Referencing the array like I have in the above example does work.

Thank you Achmed for the link to the article, brings some light to the topic.

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

HELP Find gameObject With tag in another array 1 Answer

[C#] Buttons through an Array. 1 Answer

A problem with intersection detection 1 Answer

Array empties values on RunTime? 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