How can I reseed/reset FMath:PerlinNoise(1,2,3)D() function?

I have tried FMath::RandInit but that didnt work. I have proceduraly generated terrain and I want to save it by simply saving the seed and then regenerate the terrain when map is loaded. Is there some way I can do this? Or I have to implement my own perlin noise function? Thanks in advance.

The perlin in fmath uses fixed permutation that cant be changed so I had to copy all the perlin code to my own library and write a PerlinReset() function that recalculates the permutation using FMath::RandRange(), so I can call FMath::RandInit(seed) and then call PerlinReset() and now I can save the map only by saving the seed. [HR][/HR]
Code for reseting the permutation, I guess that this code can be optimized further but works for me since I call PerlinReset only once. You also have to remove “const” keyword from the Permutation variable declaration which is in FMathPerlinHelpers namespace.



void MyPerlin::PerlinReset() {
using namespace FMathPerlinHelpers;
TArray<int> numbers;
numbers.SetNumUninitialized(256);
for (int i = 0; i < 256; ++i) {
numbers* = i;
}
for (int i = 0; i < 256; ++i) {
int index = FMath::RandRange(0, 255 - i);
Permutation* = numbers[index];
Permutation[i + 256] = numbers[index];
numbers.Remove(index);
}
};


1 Like

Good solution, thanks.
What is this assignment syntax though? I’ve never seen this.

numbers* = i;

Seems like I pasted it wrong and did not check :smile: correct is numbers[i] = i;
You can check the source here if you want. CubeCraft/Source/CubeCraft/Private/MyPerlin.cpp at master · Rinter-7/CubeCraft · GitHub