godot icon indicating copy to clipboard operation
godot copied to clipboard

Update ViewportTexture path relative to its local scene instead of the Viewport owner

Open Grandro opened this issue 1 year ago • 1 comments

Currently, ViewportTexture::_setup_local_to_scene retrieves the Viewport a ViewportTexture points to like this:

Node *vpn = p_loc_scene->get_node_or_null(path);

That is, the path stored within the ViewportTexture is assumed to be relative to its local scene.

But in the function Viewport::_update_viewport_path, which is used to maintain a valid path, the path is set relative to the owner of the Viewport. The local scene of the ViewportTexture and the owner of the Viewport don't have to be the same. This is for example the case if the owner of the Viewport is an editable instance (editable_children enabled).

This PR fixes the behaviour of Viewport::_update_viewport_path and updates the path to be relative to the local scene. Please note, that while the behaviour is correct now, Viewport::_update_viewport_path is still not always called when it needs to be. One example is when you instantiate a scene that contains a ViewportTexture and enable editable_children on it. The path should be updated now but it isn't. It will be wrong until you either set it manually again or cause Viewport::_update_viewport_path to be called.

This fix is crucial because if you suffer from this issue, the ViewportTexture path will be set invalid whenever you open the scene that contains the ViewportTexture and you have to reassign the ViewportTexture path whenever that happens...

Partly fixes: https://github.com/godotengine/godot/issues/96816 https://github.com/godotengine/godot/issues/87809 https://github.com/godotengine/godot/issues/74331 (This is a very generic issue. ViewportTexture has so many issues, that it is difficult to know which one this is about) https://github.com/godotengine/godot/issues/98117

Grandro avatar Oct 05 '24 22:10 Grandro

Fixes #98117

timoschwarzer avatar Oct 20 '24 13:10 timoschwarzer

Thanks! Congratulations on your first merged contribution! 🎉

Repiteo avatar Mar 05 '25 18:03 Repiteo