How to repeat a scene an infinite number of times

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spooikypok_Dev
:warning: Old Version Published before Godot 3 was released.

I want to make a forest whose part is in a scene, and i want to create and delete instances at relative places when the camera moves, so the forest dynamically creates and frees itself when the player goes somewhere, so it looks and feels infinite without making the computer explode? I don’t need a lot of instances at a time, because the player has a very low visibility.

I think a common approach is to create cells or areas, populate the closest ones and remove the far ones.

The distance or size of the areas may depend on player speed and sight.

With godot you can also have another level of scenes removed (from tree) to keep a cache before deleting, but careful with _ready, will be triggered on reentry.

eons | 2016-10-17 02:37

The above comment is really the correct answer.

You just need a grid of nine “cells”, with the character in the center one. If the player leaves that cell, you spawn a new row of three cells in the direction he moved (which you can determine from which cell he entered), and remove the row behind him.

For your case, the cells would create some random trees or whatever you want inside their area on ready().

rgrams | 2016-10-20 02:03

:bust_in_silhouette: Reply From: DimitriyPS

I think a better solution would be to import the trees (forest) in the independent scene with multiple levels of detail (LOD). This will determine at what distance the tree is not displayed at all. Then the scene tree to add to the scene card and clone the desired number of times.

With this approach not would be resource-intensive operations, change the scenegraph. And you will get huge optimization on the render. And all of this will work automatically.

Please explain more clearly what you mean. What’s this LOD thing?

Spooikypok_Dev | 2016-10-17 18:58

What is LOD

Here’s how it might look in the editor:
enter image description here

DimitriyPS | 2016-10-17 23:15