x


How do I SetNeighbors() for terrains before I put them in an AssetBundle?

I've got a large set of terrain tiles that I can successfully add to a prefab and use that to build an AssetBundle, but when I call SetNeighbors() on the Terrains it doesn't seem to take effect. Manually adding a script to each terrain object to call SetNeighbors() works, but that's a major pain. Is it possible to store the neighbor associations in an AssetBundle and/or a prefab? My Pro trial is up in five days and I'm still deciding whether to purchase (in other words, I'll give anyone who responds before then an automatic upvote).

New to both Unity and C#. Here's what I'm trying, minus the fat:

In a loop over tile heightmaps:

TerrainData terr_data = new TerrainData();
terr_data.SetHeights(0, 0, heightmap_tile);
GameObject terr_tile = Terrain.CreateTerrainGameObject(terr_data);

Then, when the loop is finished:

SetTerrainNeighbors(...); // Calls SetNeighbors on the Terrain component of each terr_tile GameObject. I suspect this code is fine, but I can drill down if folks want.
EditorUtility.ReplacePrefab(terr_parent_GameObject, terrain_prefab, ReplacePrefabOptions.ConnectToPrefab);
UnityEngine.Object[] terr_prefabs = AssetDatabase.LoadAllAssetsAtPath(terrain_prefab_path);
BuildAssetBundleOptions bundle_opts = BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets;
BuildPipeline.BuildAssetBundle(null, terr_prefabs, "Assets/"+prefix+"_bundle.unity3d", bundle_opts);

Suggestions?

more ▼

asked Oct 22 '10 at 07:48 PM

novo gravatar image

novo
93 5 5 11

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

1 answer: sort voted first

All I hear is crickets, so I'll attempt to provide my own answer.

I see no evidence of support for storing terrain neighbor associations in asset bundles or prefabs. The observed practice is to set neighbors as they are loaded at runtime, as in the (warning: large file) Streaming World Demo where terrain tiles are pulled from the asset bundle depending on player position. Case closed?

more ▼

answered Oct 25 '10 at 12:06 AM

novo gravatar image

novo
93 5 5 11

(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:

x1472
x382
x32
x4

asked: Oct 22 '10 at 07:48 PM

Seen: 1112 times

Last Updated: Oct 22 '10 at 07:54 PM