Dynamic terrain texture loading

hi all !

i’ve a monobehaviour script in terrain GameObject. This script load and unload texture, it run but i’ve two problemes :

* first when set the splatprototype of terrain data :

SplatPrototype splat = new SplatPrototype();
splat.texture = m_text as Texture2D;
terrainGameObject.GetComponent<Terrain>().terrainData.splatPrototypes = new SplatPrototype[] { splat };

i obtain an console error :

Do you know why i’ve this error and how to do to fix it ?

* second : i not be abble to unload texture memory :

foreach (SplatPrototype splat in terrainGameObject.GetComponent<Terrain>().terrainData.splatPrototypes) 
                DestroyImmediate(splat.texture, true);
            }
Resources.UnloadUnusedAssets();

after this, the texture has destroyed but, the quantity of busy RAM dont change.
how to do to unload terrain textures ??

can you help me. thx.

  1. Managed environments don’t free up their memory immediately, they keep the pool around for reusage unless the system resources are running out so they are forced to hand them back

yes i know that, but after few loading/unloading, unity crash → out of memory because the memory of unloaded texture is not free so i think texture is not unloaded…

For problem 1 you might just be missing this:

splat.tileSize = new Vector2(x, y);

Works for me

first tanks you for your help !

Antitheory sorry, i’ve missing to write on my first post, i set splat tile size and offset :

splat.tileSize = new Vector2(terrainGameObject.GetComponent<Terrain>().terrainData.size.x, terrainGameObject.GetComponent<Terrain>().terrainData.size.z);
splat.tileOffset = Vector2.zero;