How to create a simple world generator in Unity3D?


I’m creating a survival game, like minecraft, but instead of blocks, I have some simpler geometry, somehow similar to the geometry style in The Long Dark or Unturned. I’m going to create a simple world generator, but I don’t really know how I can do it, so I have some questions:

Creating and Saving

  • Can I create a new empty Scene from a C# script?
  • (If above is possible) Can I start to populate the new Scene, from a C# script?
  • (If above is possible) Can I serialize/save everything in the Scene, or just save the Scene as a .unity file, from a C# script?


I have thought of two ways of doing the generation. Either generate a Terrain, or to create a new flat (plane) Mesh and use the Diamond Square Algorithm to place some vertecies with random heights on it, to create a simpler terrain. I think the last one siuts best to the rest of my game’s “geometry style”, so thats the one that I want most, if it’s possible, but I don’t know (if I can) how I can do that from a C# script in unity.

I also want to populate it with some trees, bushes, entities, structures etc. but I have an idea of how I can do that. I will just simply cast some raycast, and check if they hit the ground, and if they do, I’ll randomly (with some kind of seeding) select one object and place it where the hit occurred. In that way, I can decide how many objects I want, by changeing the number of casted raycasts. I can also extend it so that I can controll how many of each object that will be spawned.


I want to, from a C# script, create a new Scene, generate a new flat mesh and use the Diamond Square Algorithm to place vertecies with random heights on it, so that it looks like a terrain, something like this, which demonstrates the Diamond Square Algorithm, and start to populate it with structures, foilage, entities etc. Lastly, I, also from a C# script, want to serialize/save the Scene, or all objects in the Scene, to a file.

All help is greatly appreciated!

// TheDDestroyer12

You have a really well put together post and the project sounds interesting. But with no proper question this post would be a lot better suited on the forums as Unity Answers is for specific technical questions.

One place to start is to search around for Unity World Generation. There are a lot of people that have done something similar, and there might even be some plugins on the Asset Store that can help you greatly.

Good luck on your project.