Using some c# to modify a terrain heightmap in the editor results in the heightmap changes being lost when closing the editor and re-opening.
Replication:
Create new project
Add the following script to Source/ Game/
using System;
using FlaxEngine;
using FlaxEditor.CustomEditors.Elements;
#if FLAX_EDITOR
using FlaxEditor.CustomEditors.Editors;
using FlaxEditor.CustomEditors;
namespace TerrainSystem
{
[CustomEditor(typeof(Terrain))]
public class Reproducer : GenericEditor
{
public override DisplayStyle Style => DisplayStyle.Inline;
public override void Initialize(LayoutElementsContainer layout)
{
base.Initialize(layout);
Terrain terrain = (Terrain)this.Values[0];
layout.Label("Not Saved:", TextAlignment.Near);
layout.Space(10);
ButtonElement button = layout.Button("Generate Height Map", Color.Gray);
button.Button.Clicked += () => GenerateMap(terrain);
}
private void GenerateMap(Terrain terrain)
{
Debug.Log("Updating heightmap");
int heightMapSize = terrain.ChunkSize * FlaxEngine.Terrain.PatchEdgeChunksCount + 1;
int mapSize = 509;
int heightMapLength = heightMapSize * heightMapSize;
float[] heightmap = new float[heightMapLength];
Random rnd = new Random();
for (int y = 0; y < mapSize; y++)
{
for (int x = 0; x < mapSize; x++)
{
heightmap[y * mapSize + x] = ((float)rnd.NextDouble()) * 500;
}
}
Int2 patchCoord = new Int2(0, 0);
terrain.SetupPatchHeightMap(ref patchCoord, heightmap, null, true);
}
}
}
#endif
Create a new terrain, scroll to the bottom of properties and click “Generate Height Map”
You will see a random noise heightmap. Save All.
Upon re-loading the scene, the height map data is lost. There also seem to be some robustness issues with the terrain material data being lost on re-load. But the loss of height map data is apparent regardless of the terrain material being set to Default Terrain Material or left blank.
After a while of doing this data can be seen accumulating in Content/ SceneData/ Scene/ Terrain/ as previously generated heightmap data.