Hello everyone,
My question is a littlebit complicated… I want to create terrains at runtime (because I didn’t saw any class to set the terrain Width at runtime). So how can I create terrains with thier own TerrainData at runtime?
Hello everyone,
My question is a littlebit complicated… I want to create terrains at runtime (because I didn’t saw any class to set the terrain Width at runtime). So how can I create terrains with thier own TerrainData at runtime?
You have to make your own mesh I think.
But the terrain depends on the runtime actions. I can’t create a pre-made terrain that’s the problame. Or if I create a mesh, I can set it’s scale and I can create for example “hill’s” on it randomly?
Read the documentation thoroughly and carefully for both Terrain and TerrainData.
All the variables and functions you see in the documentation you’ll need to populate. I generate unique terrains at runtime all the time, so if you run into any specific question/issue I’ll gladly help you. However, the best first step is to read through and try to understand:
Basically though, the generation idea is to do something like
TerrainData generatedData = new TerrainData();
// Then go through all those variables you see in the documentation and fill them in with your desired results.
Terrain generatedTerrain = Terrain.CreateTerrainGameObject(generatedData).GetComponent<Terrain>();
// Fill out all the terrain side things with your desired results..
Terrain.Flush();
EDIT:
Quick note… the “alphamaps” actually refer to the splat texture alphas - not the heightmap.
And is there any way, that I call the new TerrainData(); with a heightmapWidth and heightmapHeight? Because after I got the generatedData, the height and the width is read only :S… I know the original issue was not this, but if it’s possible, it can save me a lot hour of coding…
Not sure if you still need a response to this, but the HeightmapWidth/Height probably aren’t what you think they are. You want HeightmapResolution (and yea, it’s gotta be a square).