- Home /
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?
Answer by novo · Oct 25, 2010 at 12:06 AM
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?
Your answer
Follow this Question
Related Questions
How to import the object from server to unity 2 Answers
How do I find a hidden shader? 1 Answer
How can I use a tile set to texture a large mesh? 1 Answer
Terrain Tile Seams and Terrain.SetNeighbor 1 Answer
Blend edges between multi terrains 0 Answers