x


Finding GameObjects across folders

Suppose you have a folder structure as follows:

Scenes --> Scene_001 containing ( scene_1, script_1.js, SceneObject_1 )
Scenes --> Scene_002 containing ( scene_2, script_2.js, SceneObject_2 )
Standard Assets -- > (all the normal things here)

I have attached the scripts to their respective scene objects; ie script_1 was drag connected to SceneObject_1, and so on.

What I would like to do is have script_1 execute a function in script_2. I tried to use

var x = GameObject.Find("SceneObject_2") 

as well as

var x = GameObject.Find("/SceneObject_2")

to get a handle on the SceneObject_2. It simply can not find the object. So, how do we find game objects that are not in the same scene and not in the same folder?

more ▼

asked Mar 14 '10 at 07:13 PM

Kirkja gravatar image

Kirkja
26 5 6 10

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

1 answer: sort voted first

There is no folder structure in the hierarchy; you can have objects be parents and children but they are all in one "folder". GameObject.Find will find any object in the scene by name regardless. It will not find any objects in different scenes, since those objects do not exist until they are loaded.

more ▼

answered Mar 14 '10 at 07:21 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 521

Does this mean that scripts, game objects, and scenes must all reside at the same location in order to inter-operate? If so, doesn't this make larger projects harder to build and maintain if you can't partition the code base into logic sections.

I'm definitely new to this environment, so I'd like to get off to a solid start. Thanks!

Mar 14 '10 at 10:45 PM Kirkja

All assets for a project must be in the same project folder. You can make different folders in which to put scripts, prefabs, textures, etc., so you can organize a project however you want. Make sure you understand the difference between the project tab (everything in your project) and the hierarchy tab (all game objects in a given scene, which are the only things that GameObject.Find works with).

Mar 14 '10 at 11:48 PM Eric5h5
(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:

x2087
x207
x72

asked: Mar 14 '10 at 07:13 PM

Seen: 1617 times

Last Updated: Mar 14 '10 at 08:04 PM