x


Whats the best way to access other Game Objects?

There are many ways to access other game objects in unity. I think using tag is the easiest way for me because I dont need to pay attention to the object's hierarchy. But it may take cost compared to other ways.

http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

Could you tell me your opinion about this?

more ▼

asked Dec 05 '11 at 03:56 AM

JKLs gravatar image

JKLs
31 5 5 5

sorry to be a stickler, this is more a question and answer place than a forum, best to stick this discussion thread on the forum :)

As for what this is talking about, you just use objects as the 'pointer' to them

Dec 05 '11 at 04:04 AM milali

Tags can be slow, but you can use them if there's only one object you need to get at a time. Otherwise, just do it the usual programming way- keep references to all the objects you want to have access to, and pass them around in code. That's the fastest way (much better than using string lookups, which is what tags are).

Dec 05 '11 at 04:13 AM syclamoth
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Well i have used several ways to access Game Objects and it depends on the situation there is no better way of doing it. Tags access the whole game object/s and Get Component accesses a script/component from a certain Game Object.

more ▼

answered Dec 05 '11 at 04:05 AM

DGArtistsInc gravatar image

DGArtistsInc
269 8 15 19

(comments are locked)
10|3000 characters needed characters left

If you consider object lookup performance in runtime then using fixed referenced object in inspector is the best choice .In that case unity has early bound reference to the object which does not suffer from enumeration cost. For that reason, using GameObject.find(...) in Update() is worst way to go.

more ▼

answered Dec 05 '11 at 06:32 AM

suruz@kento gravatar image

suruz@kento
76 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2096
x326
x208
x153

asked: Dec 05 '11 at 03:56 AM

Seen: 851 times

Last Updated: Dec 05 '11 at 06:37 AM