- Home /
Editing Terrain prefabs directly from a custom editor window. Updates not applying to scene instances.
I am using a custom editor window to automate changes to a 4x4 grid of terrain prefabs. The problem is that some Terrain variable changes do not seem to propagate out to scene instances immediately.
![]()
For example, here you can see that when I select the prefab in the project folder the pixel error value has been set to 5 via my editor window, but below that is an image showing that the prefab instance in the scene still has the old value of 2 for the pixel error.
![]()
However, after entering play mode once the values then seem to update properly in the inspector (and reflect those changes in the scene view as well). Is there a way to force this update via code rather than needing to enter play mode?
I get the reference to my terrain GameObject prefab in the project folder using the AssetDatabase.LoadAssetAtPath method and call the following function on that prefab:
void ApplyTerrainSettings(GameObject terrainGo) {
//Terrain Settings
basemapDistance = 1000;
castShadows = true;
detailObjectDensity = 1.0f;
detailObjectDistance = 70;
heightmapPixelError = 5;
//Terrain Data Settings
terrainWidth = 2000;
terrainLength = 2000;
terrainHeight = 4250; //Combine for terrainData.size Vector3
heightmapResolution = 2049; //Heightmap Resolution
detailResolution = 1024; //Detail Splatmap Resolution
detailResolutionPerPatch = 16; //Detail Splatmap Resolution Per Patch
alphamapResolution = 2048; //Control Texture Resolution
baseMapResolution = 1024; //Base Texture Resolution
Terrain terrainComp = terrainGo.GetComponent<Terrain>() as Terrain;
terrainComp.basemapDistance = basemapDistance;
terrainComp.castShadows = castShadows;
terrainComp.detailObjectDensity = detailObjectDensity;
terrainComp.detailObjectDistance = detailObjectDistance;
terrainComp.heightmapPixelError = heightmapPixelError;
terrainComp.terrainData.size = new Vector3(terrainWidth, terrainHeight, terrainLength);
terrainComp.terrainData.heightmapResolution = heightmapResolution;
terrainComp.terrainData.SetDetailResolution(detailResolution, detailResolutionPerPatch);
terrainComp.terrainData.alphamapResolution = alphamapResolution;
terrainComp.terrainData.baseMapResolution = baseMapResolution;
terrainComp.Flush();
EditorUtility.SetDirty(terrainGo);
}
Your answer
Follow this Question
Related Questions
Editor script instantiating prefab and maintaining link? 4 Answers
Editor Script: Linking GameObjects to public script variables resets when playing. 1 Answer
Terrain: Use as scenario (individual) and prefab (unchanged, reusable) 0 Answers
Instantiating multiple objects, Destroying and instantiating on trigger + delay 0 Answers