0 votes

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.

in Engine by (24 points)

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.

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().

1 Answer

0 votes

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.

by (353 points)

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

What is LOD

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.