puchik / godot-extras

LOD and optimization C++ addons and shaders for Godot 4 and Godot 3
137 stars 14 forks source link

Objects not processing after scene changes, losing registration #6

Closed TokisanGames closed 2 years ago

TokisanGames commented 2 years ago

On my game I have a global camera, as well as the global MTLOD/LodManager. When switching back and forth between scenes, some previously instantiated assets are removed from the tree and get added again. This causes them to stop changing LODs. Neither the LODManager nor the camera have changed or been removed from the tree, only the assets. Though my previous design did remove and add different cameras upon scene changes.

If I specify print("Setting camera: ", LodManager.set_camera(path_to_my_camera)) upon scene loads I get true, and during the first scene load, the LODs change on the assets as without this line. However, upon disconnecting and reconnecting the scene (assets remain instantiated), they stop changing LODs, even though I specify set_camera in _enter_tree() as soon as the scene loads. set_up_camera does the same thing.

It looks like you are registering objects with LodManager in _ready() instead of _enter_tree(), though I think it belongs in the latter or both. https://github.com/puchik/godot-extras/blob/24f8d7471ca3f5a3576abb00a70ba4381558ceed/gdnative/multi-lod/src/lod.cpp#L133

Here you are removing their registration as soon as they leave the tree. https://github.com/puchik/godot-extras/blob/24f8d7471ca3f5a3576abb00a70ba4381558ceed/gdnative/multi-lod/src/lod.cpp#L62

Adding and removing objects from the tree is the primary way for levels to be loaded or objects streamed in and out, so they need to register on _enter_tree.

puchik commented 2 years ago

Fixed by 57e595bfc0a8d787615c03369f1e116bdbbe484d

TokisanGames commented 2 years ago

This works, thanks for the update.