Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback procedural world generator - Feedback

Discussion in 'Works In Progress - Archive' started by dbugger, Sep 24, 2019.

  1. dbugger

    dbugger

    Joined:
    Jan 10, 2013
    Posts:
    55
    Hello fellow users,

    I am building a world generator that is based on Perlin Noise to create procedurally generated worlds. The world has some biomes defined, and each biome has a set of terrains, as well as different props. This is what I had after the first try.



    It took me a lot of time to make it performant, but now it seems to work quite fine. It took me quite a lot of work to create the map using chunks, and how to load them asynchronously. Before that, the game froze for half a second, each time chunks had to be re-drawn.

    Once that was done, I added the prop rendering for each biome:



    Everything in this map is done with Perlin noise:
    • Heights
    • Biomes
    • Terrains
    • Props
    After that I started adding NavMeshSurfaces for the AI to navigate the world, but when I did this, the small freeze that happened every time chunks re-rendered came back. This is the problem I am trying to solve right now.

    Things that I have used to solve the challenges I have met so far are the following:
    • Data preloader: I have an object that pre-loads all the data for all neaby chunks, in case the player moves into its direction. This is done in another thread, so that it does not impact performance.
    • GameObject pools: Instantiating is expensive, so I use pools to reuse already-instantiated objects
    • Cache: Previously values calculated with Perlin Noise will be stored for a long term, and only deleted under certain circumstances (to avoid having the memory growing endlessly)

    Even though it would be nice if someone could help me with my problem for the navmesh, I would really like any kind of feedback with my code, since I am quite inexpert with C# and I am surely doing many things in a very costful manner.

    The source code can be found here: https://github.com/enriquemorenotent/world-renderer-review

    It is developer with 2019.1. If you can take a look at it, and give me your feedback about the code, I would appreciate it a lot.

    Thanks!

    PS: You can disable the rendering of props and navmesh inside the main world generator controller, in case that you want to compare the performance any of those components add.
     
    DBarlok likes this.
  2. DBarlok

    DBarlok

    Joined:
    Apr 24, 2013
    Posts:
    268
    Last edited: Sep 27, 2019
  3. dbugger

    dbugger

    Joined:
    Jan 10, 2013
    Posts:
    55
    Depends on the size of the mesh, but I definitely get a small "freeze", whenever I have to rebuild it.