- Home /
Setting SplatPrototypes is very slow! (50 ms every Terrain), coroutines/threading? (I need suggestions)
Hi! well I'm making a landscape generator, now I'm optimizing it, because it works with a grid system (9 terrains) and when I assign the SplatPrototypes (ground textures) to every Terrain it lasts 50 ms for each Terrain, so 50 ms * 9 = 450 ms, the game freezes about a second (because it loads more things, like Heightmaps, Splatmapping, etc)
This is my code:
//This are the textures depending on the biome (Length = 4)
SplatPrototype[] mapTextures = new SplatPrototype[t.myBiome.biomeTextures.Length];
for(int i = 0; i < t.myBiome.biomeTextures.Length; i++) {
mapTextures[i] = new SplatPrototype();
mapTextures[i].texture = t.myBiome.biomeTextures[i];
mapTextures[i].tileOffset = new Vector2(0, 0);
mapTextures[i].tileSize = new Vector2(15, 15);
mapTextures[i].texture.Apply();
}
//Until here I spent only 1 ms... The next block will last 50 ms!
GetComponent<Terrain>().terrainData.splatPrototypes = mapTextures;
And this is what I use for measure it:
var watch = Stopwatch.StartNew();
//Code...
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;
Debug.Log("It lasts "+elapsedMs+" ms");
I know that when you set this variable terrainData.splatPrototypes the texture are set into the scene automatically, maybe this is my problem...
Yesterday, I thought that the best option would be to call this part of code in a "background" area, where the main thread wheren't affected by heavy calls.
I tried to solve it with Threading or Coroutines by searching into Google, but, (obviously) with any luck :/
What do you recommend me to do, to search, or to make?
Thanks in advance!
Bye.
Your answer
Follow this Question
Related Questions
Best Practice for Multithreading Procedural Terrain Generation? 1 Answer
How to make a function wait untill a specific bool is true? 2 Answers
DOTS Jobs memory leak and game freezing 1 Answer
Optimizing the generation of a procedural world - 50ms lag spike to 1 Answer
Can't get while loop to execute more than once in a coroutine before yielding [Solved] 2 Answers