Search Unity

Question Handle adding content with seed generation

Discussion in 'Scripting' started by Finijumper, Mar 7, 2021.

  1. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    Hi, I'm making a level generator that picks a random chunk index that goes from 0 to chunks count - 1. In the beginning I set a seed so that I can save it and regenerate the same level afterwards.

    The problem is that if I add more chunks to the system the previously saved seeds won't work (the level generated will be different) because the range of the randomized index has changed.

    Any tips on how I could always get the same results even after adding new types of chunks?

    Thanks.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Assuming you only add chunks and never rearrange or remove them, you could simply save the number of chunks that were available when the level was generated alongside the seed. So now instead of your seed consisting of one numer (the random seed) it consists of two numbers (the random seed and the number of chunks that were available when you generated the level the first time. You could encode this data into one single longer string or number value that the player can use to generate the level.

    Then when you generate a level from the seed, you only do Random.Range with the provided range from the seed.
     
    Finijumper likes this.
  3. Finijumper

    Finijumper

    Joined:
    Jul 12, 2016
    Posts:
    79
    Yeah that's the solution that I came up with but I wanted to see if there were any alternatives without having to save extra parameters. I wonder how games like Minecraft handle this.