0 votes

The player can open this menu whenever in game proper. The problem is, as the menu is created as a child within the Player node, and the player is in the YSort of the scene, the menu is also obeying the sorting.

The problem: the menu doesn't show on top of other sprites
I'm currently thinking of putting the code to create the instance of the menu on the map scene instead of the player script, so it can stay out of the YSort. But if I have too many maps, this will become a hassle.

How the scene's currently arranged

Is there a way to make a child node ignore the YSort? Or is there a way to make a Control node to ignore the parent's relative Z, or set its own? I have tried set("z_index", 3) and set("z_as_relative", false) on the created instance, before adding it as a child, but it didn't make a difference.

Godot version 3.3.3
in Engine by (292 points)

The canvas_items nodes have the property show on top and the function set as top level. I do not know if they can work in this case but you can try.
https://docs.godotengine.org/en/stable/classes/class_canvasitem.html

1 Answer

0 votes
Best answer

Thanks to the comment from @estebanmolca, I've managed to resolve this! Thanks, man!

So, first I tried instance.set("show_on_top", true) before add_child(instance), but nothing happened. Then, I tried instance.set_as_top_level(true) next, which made the menu not show up at all, not even behind the tileset. I found that very weird.

After further messing around, I noticed that the menu was actually showing when "showontop" was true, but it was using the scene's origin instead of the player position! Since the player's starting position on the scene was far from it, I couldn't see it right away.

So, I had to do this:

instance = pausemenu.instance()
instance.set_as_top_level(true)
instance.set_position(position) #the position parameter here is the Player's

At first, the only problem was that the menu was being drawn down and right from the player's origin. I had to mess around with the rectangle's (the main node of the menu) anchor until it aligned up properly.

EDIT: After having trouble with the menu showing under anything that had a Z greater than the player's, including a tileset, I found the definitive solution: create a Node2D with a non-relative, high Z Index and add_child from within it, like this:

#menulayer is a Node2D. It's sole purpose is to have a big z index
pauseinstance = pausemenu.instance()
$menulayer.add_child(pauseinstance)
by (292 points)
edited by
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 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 webmaster@godotengine.org with your username.