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 code-blep · Oct 03, 2012 at 07:57 PM · transformarraynameindexsearch

Find index number in an Array of a transform by it's name

Hi,

I have an array which is populated with transforms like this:

 var attackerClonesArray = new List.<Transform>();

I am trying to find the index number of a transform in the array by searching for it's name.

I am getting the transform name like this:

 var thisTransformName : String;
 thisTransformName = transform.name;

My goal is to then erase that transform from the array. I've tried an number of solutions such as index and other stuff but can't seem to quite get it.

Any suggestions?

Thanks

Paul

Comment
Add comment · Show 5
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 AlucardJay · Oct 03, 2012 at 08:15 PM 1
Share

untested theory

 var myPlaceInArray : int = -1;
 
 for (var i:int = 0; i < attackerClonesArray.length; i ++)
 {
     if ( attackerClonesArray[i] == thisTransformName )
     {
         attackerClonesArray[i] = null;
         myPlaceInArray = i;
     }
 }
 
avatar image code-blep · Oct 03, 2012 at 08:49 PM 0
Share

Thanks Alucardj! Will give this a go if I have no success with Fattie's suggestion, but it looks good so this gets a like ;)

avatar image AlucardJay · Oct 03, 2012 at 08:54 PM 0
Share

No worries, thankyou. If you want to use dynamic lists (as Fattie states, never use dynamic arrays) absolutely go with the answer (I would!).

However I would like to make a case for static arrays. I did some research a while back and found that Static arrays are infact more efficient than List. Surprising but yes. If there are any other considerations with using arrays in unity I am not aware of, then I am certainly open to advice.

avatar image Fattie · Oct 03, 2012 at 09:01 PM 0
Share

dude -- if you mean absolutely plain arrays (like same as arrays in c .. a block of memory), yes that is 18 million billion times more efficient

that's why they are used for the mesh of course, for instance.

but "javascript arrays" are toss, never use them

here !

http://answers.unity3d.com/questions/198318/javascript-array-use-with-a-struct-.html

avatar image AlucardJay · Oct 03, 2012 at 09:13 PM 0
Share

You got me. $$anonymous$$y research was purely derived from using static arrays for meshes. As I mentioned above, I would absolutely not even consider using a dynamic array, but havn't had the need for dynamic Lists much as yet, so am still very green when it comes to the commands available there. A couple of times I have forgotten to include import System.Collections.Generic; which led to headaches for I did not understand. That was an excellent link, thanks.

1 Reply

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

Answer by Fattie · Oct 03, 2012 at 08:24 PM

do NOT use arrays. use List.

never, ever use arrays in Unity.

as well, once you do use List, you have all these available to you ...

http://msdn.microsoft.com/en-us/library/d9hw1as6(v=vs.90).aspx

you can do it with a couple lines of code

Comment
Add comment · Show 8 · 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 code-blep · Oct 03, 2012 at 08:33 PM 0
Share

Hi Fattie. Is list available via UnityScript?

avatar image Fattie · Oct 03, 2012 at 08:46 PM 2
Share

for sure, it is central to unityscript

(that link is just a handy reference for the many List commands.)

suggest you post a question "please explain how to use List to me"

import System.Collections.Generic;

bb = new List.();

bb.Add( something )

bb[2].position

bb.RemoveAt( 3 )

sort, reverse, find, .. heaven

it's incredibly easy. never use arrays.

plus they are much faster etc

there must be a godo list tutorial somewhere ask a questino

please tick and vote me here :-)

avatar image code-blep · Oct 03, 2012 at 08:50 PM 0
Share

This looks great. Looks like I'm investigating List tonight ;) Thanks for the advice Fattie.

avatar image Fattie · Oct 03, 2012 at 08:51 PM 0
Share

don't put any effort in to it! just ask here and someone else will do all the work man! there must be a great tute out there someone here will know.

it would be the best question on the site for a week. cheers

avatar image code-blep · Oct 04, 2012 at 07:51 PM 0
Share

O$$anonymous$$ people. Fattie was right. Lists rock. Here is a continuation of the subject here: http://answers.unity3d.com/questions/327065/explanation-on-how-to-use-list-in-unityscript.html

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

11 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

Related Questions

Array of transform index out of range error 1 Answer

Explanation on how to use LIST<> in UnityScript 2 Answers

IndexOutOfRangeExeption - Array index is out of range 2 Answers

EditorGUILayout Array 1 Answer

move enemy to random transform array 2 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