x


Extracting GameObject from scene package

I have a scene in Unity that is exported as a package using the following code:

string outputPath = sceneName + ".unity3d";
string result = BuildPipeline.BuildPlayer(new[] { inputPath }, outputPath,
    BuildTarget.StandaloneWindows, 
    BuildOptions.BuildAdditionalStreamedScenes);

When I load the package during runtime, I use a WWW like this:

var www = new WWW(packageUrl);
var ab = www.assetBundle;
Application.LoadLevel(sceneName);

I want to retrieve the terrain from the scene. In Unity, the terrain is just called "island_terrain" and is part of the scene which is packaged above. How would I go about getting the terrain GameObject/Component?

more ▼

asked Aug 29 '12 at 12:45 AM

lukegravitt gravatar image

lukegravitt
18 2

I was eventually able to get it to work by doing

GameObject.FindObjectOfType(typeof(Terrain));

but I still feel this is suboptimal.

Aug 29 '12 at 03:49 AM lukegravitt
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
GameObject.Find("/island_terrain");
more ▼

answered Aug 29 '12 at 02:42 PM

Paulius Liekis gravatar image

Paulius Liekis
7.3k 16 24 47

Heh, turns out this wasn't working for me because my GetComponent call had a lowercase t in Terrain, so it was returning null. It works now. Thanks!

Aug 29 '12 at 06:09 PM lukegravitt
(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:

x1521
x744
x98

asked: Aug 29 '12 at 12:45 AM

Seen: 258 times

Last Updated: Aug 29 '12 at 06:09 PM