I want get a copy terrainData B of a exist terrainData A.
TerrainData terrainData = new TerrainData();
// copy terrain data
terrainData.RefreshPrototypes();
Terrain workTerrain = (Terrain)Terrain.CreateTerrainGameObject(terrainData).GetComponent(typeof(Terrain));
workTerrain.Flush();
The terrain render correctly, but if i save the terrainData B, it’s alphamap is miss, don’t render correctly.
AssetDatabase.CreateAsset(terrainData, newAssetPath);
Why?
Thanks.
I call SyncTexture on the terrainData, it report a argumentexception:
ArgumentException: Unrecognized terrain texture name: “SplatAlpha 0”
for (int j = 0; j < terrainData.alphamapTextureCount; j++)
{
terrainData.SyncTexture(terrainData.alphamapTextures[j].name);
}
You have to use the function with a hardcoded string to indicate you want to sync a splatmap.
terrainData.SyncTexture(TerrainData.AlphamapTextureName);
Only have to call this once, it will sync all the splatmaps the terrain contains. You can find the source code reference here: https://github.com/Unity-Technologies/UnityCsReference/blob/master/Modules/Terrain/Public/TerrainData.GPUCopy.cs
1 Like
Thanks.
SyncTexture work now, but if i call CreateAsset, the alphamap is still missed.
1 Like