0 votes

So I am doing a map generator, when the player reaches certain x position a tilemap is loaded and another is distroyed I use the following code to do this:

func _on_createa2_body_entered(body):
    print("create")
    total_distance = total_distance + 1024
    var new_tile = TileMap1.instance()
    new_tile.position.x = total_distance
    tiles.push_back(new_tile)
    #Here I add the instance to the tree
    get_tree().get_root().get_child(0).get_node("Tiles").add_child(new_tile)
    pass 


func _on_destroya2_body_entered(body):
    print("destroy")
    var arreglo = tiles.pop_front()
    #Here I remove the node
    arreglo.queue_free()
    pass 

For some reason the games slowdown, I read into object pooling but some dev a time ago said that was not necessary in godot so I dont know what to do.

in Engine by (22 points)
edited by

1 Answer

0 votes

What do you expect you'll get as an answer here? If someone said "pooling is not needed" he maybe meant "godot has good memory management" he didn't meant "instancing new objects won't take any cpu".

In 60 FPS environment, there is only 15 ms to load your tilemap without framedrop (as you probably know). If your tilemap is big or has many objects you have to expect some cpu usage.

But.. you allways have options for sure, at first read this: https://docs.godotengine.org/en/stable/tutorials/io/background_loading.html

But a simpler solution may be reducing your tilemap sizes (make more chunks). Or preload them when player is inactive (reading text, mixing potions, opening inventory and so on) if possible.

by (204 points)
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.