I’ve made a prefab wich generates other prefabs, to make a terrain. Now, I need to make this terrain infinite. What I thought of is to make a script that creates automatically the prefab-making prefab, but, to make the game not create the entire world once, I need to know if I can create an inactive by default prefab, and activate it only if it is in a range chosen by me or the player. Is it possible?
You can’t create an infinite world by instantiating inactive prefabs. You would need a (smaller) infinite number of them!
You’ll probably want to make an algorithm that will generate terrain of a certain square size (which it sounds like you might have done already), and add (and remove!) them as the player moves around. Do not forget the remove part!
A lot of open world games take this kind of approach (although typically they load data rather than generate it, of course)
Depending how big/detailed they are, you’ll probably want at least 9 active at a time. One in the centre, 4 direct adjacents and 4 diagonal adjacents.
If you want to make all players have the same “random” world, you can set the seed for the random number generator you use to build the world.
I have semi-infinite terrain generation(almost infinite) and the way i surround the player in them is at the start i make the first 9 tiles or so. Then when the player steps onto on one of those tiles the game will search in the 9(or so) tiles around that tile and if their is empty space it will create a new one.
Hope it makes sense.
We have created thousands (>100k) of Unity terrains with different levels of detail from the SRTM data at NASA. There is a video of an interactive fly-over with 1/4th of the data at youtube, and another one with full resolution and an interpolated camera path. Frame-rate of the first video is slower as we calculate splatmaps dynamically, they are pre-calculated in the second video.
The challenge is the sheer size of it. Unity will throw warnings if you have any coordinates >100k and for a convincing impression and actual “walk-size”, you’d need a size of 40.000.000 x 20.000.000. As such, you need to move the terrain under a camera fixed at (0,0,0), but this will complicate the placing of any other object.