The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

I have created a GUI via Control nodes that is added to the screen dynamically like this:

onready var sub_menu_container = $MainMenu/SubMenu

var construction_menu = preload("res://gui/construction/construction_menu.tscn")
var sub_menu_scene = null

sub_menu_scene = construction_menu.instance()

Then later when I click on to a button (which is part of that dynamically added GUI) that GUI itself is removed again:

sub_menu_scene = null

When that happens (i.e. removing the GUI node again) I also set the mouse cursor:


However, now this new cursor is only shown on the part of the game window that was not where the GUI has been shown. When I move the mouse over that area where the GUI has been, then the cursor switches back to the default ARROW again - as if the GUI would still be visible. But I have removed it before, as show above, via remove_child().

Minimal Sample Project
You can find all code to reproduce this error in the minimal sample project that I have created. in the scene res://gui/main/main_gui.tscn and in its script res://gui/main/ There the GUI is added and removed to the current scene in the main_button_pressed() function, and the cursor is set in line 33 in the construction_item_selected() function.

Open the project, run the game, then click on this one single menu item in the top left corner. Then in the sub menu that opens click the one new button. Now the sub menu is hidden again - the cursor is set to the new shape only on the right part of the game window. When moving the mouse left again, on to the area where the sub menu has been, then the normal ARROW cursor is shown. You can now move the cursor left and right to see the cursor image change between the two shapes.

You can find this minimal sample project here.

Godot version 3.2.3 stable
in Engine by (30 points)

1 Answer

+1 vote
Best answer

The cursor shape only applies to all areas outside the (now empty) menu container, which will not automatically shrink after the instanced scene is removed.

You can force-shrink the container by adding

sub_menu_container.get_parent_control().rect_size.x = 0

in line 20 of

by (1,732 points)
selected by

Ohh yes indeed - thank you very much!

By the way, did you just know that from your experience with Godot, or did you debug that issue somehow and found the solution? If so, could you please be so kind and explain how you found that solution?

I started with debugging: I examined the remote tree while running the program and noticed that (1) yes, the submenu was indeed removed (as expected), but (2) the rect size of the parent container was not changed after that. So I googled "hboxcontainer shrink issue" to make sure this isn't a known bug, and the very first hit was a lengthy discussion about exactly this behaviour, which (as it turned out) is both expected and desired. So I googled some more to find the best approach to cope with this, and found a forum post with the promising title "How to force a container to updates it's size when the size of it's children changes". And indeed, there was the line I was looking for: "The key here is adjusting the parent rect size with getparentcontrol().rect_size"

Awesome, thanks a lot, Thomas.

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 Frequently asked questions and 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 [email protected] with your username.