How large is too large for a single scene?

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

This is a more general game development type question but I’m sure there’s a godot specific answer. Im working on a 2D game that is a huge open world map with lots of enemies roaming around. It’s starting to look like my entire game will be contained in one scene (most of the other objects will have their own scenes but will be instanced to the main map). I’m thinking since this is not a graphically or memory demanding type game, I can get away with just instancing everything right at the start right? Like 100 or so enemies roaming the map. I want some enemies to have set routes and I don’t know if instantiating them later by some trigger would get the desired effect. What do you guys think? As far as the size of the map, the tilemap area is 20 by 20 with each tile at 1000 pixels squared each.

:bust_in_silhouette: Reply From: 807

Problem is not map size, problem is number of objects. You can go with 2 or 3 thousand of nodes in scene. Charge times, memory allocation, fluidity can be problematic with more. trying to instance a node in a scene with tens of thousand of nodes can lag the game. I think that godot scenetree is not designed to handle tens of thousands of nodes at the same time. 100 enemies without AI are not problem, 100 enemies making calculations in all frames can be problematic. You should investigate this node:

Thanks for the response. I think that node is exactly what I need. If I give each enemy a big enough vis-notifier i can have them spawn when somewhat close and despawn a ways away where if you were to follow them where they went off screen it won’t be like they were just waiting right at the edge where they left off. If that makes any sense.

thatsalottadimp | 2018-01-10 19:43

He’s right. I was testing a prototype for my top-down shooter and tried using a massive tilemap of a single tile resource for the level, 3 enemies with real-time (process method) player-chasing scripts (nav2d), and a StaticBody2d wall at each edge. Experienced insane lag (~2 fps) but only when I tried moving my player towards the level edges. Wrongly concluded that Godot simply couldn’t handle very large tilemaps. Read the above comment and tried again, this time without any enemies on the map and, voila, 60 fps. So it’s not the map size, it’s the real-time processing of AI entities that can cause lag. I guess the same logic is used in procedurally-generated infinite map games like Minecraft and Terraria. Only entities like mobs that are close enough to the player are allowed to performs calculations and far entities are simply “not processed”. Thanks so much.

Hansel D’silva | 2020-03-10 16:05