- Home /
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?
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
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 program$$anonymous$$g 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).
Answer by suruz@kento · Dec 05, 2011 at 06:32 AM
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.
Answer by DGArtistsInc · Dec 05, 2011 at 04:05 AM
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.