Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing Node2D and Control causes issues with set_as_toplevel #42822

Closed
Zoomulator opened this issue Oct 15, 2020 · 2 comments · Fixed by #67507
Closed

Mixing Node2D and Control causes issues with set_as_toplevel #42822

Zoomulator opened this issue Oct 15, 2020 · 2 comments · Fixed by #67507

Comments

@Zoomulator
Copy link

Godot version:
3.2.3

OS/device including version:
Window 10, 19041.508

Issue description:
Input is not handled correctly in the provided reproduction project.

The project has a hierarchy Control -> Node2D -> Control.
Using set_as_toplevel(true) on the Node2D after adding it to the scene tree will cause the child Control to ignore input.

Removing and re-attaching the Node2D node will fix the behavior, letting the child Control receive input again.

If set_as_toplevel(true) is used before the Node2D is attached it works as expected.

Steps to reproduce:
See minimal reproduction.

  • Try to click the "click me" control. It will flash red if it received the click, but it doesn't work.
  • Click the top left button "Reattach"
  • Click the "click me" control again, it should now flash red when clicked.

You can move the set_as_toplevel(true) line in Main.gd to before the add_child call and it will also work.

Minimal reproduction project:
toplevel-bug.zip

@gvaneyck
Copy link
Contributor

gvaneyck commented Oct 19, 2020

Code reason this happens:

  • Since the new node has a parent Control object and is not yet marked as top level, it does not get added as a gui root control (no call to get_viewport()->_gui_add_root_control(this)) in Control::_notification(NOTIFICATION_ENTER_CANVAS)
  • CanvasItem::set_as_toplevel() calls CanvasItem::_exit_canvas() and CanvasItem::_enter_canvas() when the node is in the tree, but those will not do a Control::_notification, so the gui root control will not be attached (or detached)

@Sauermann
Copy link
Contributor

Here is a MRP for Godot 4:
toplevel-bug-4.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants