Node being drawn under another

Godot Version

4.3.3

Question

`Hello !
I’ve been working on a drag and drop system that allow to place item on slots, and drag the around like you can see in the video. Everything works as intended, except when I put a VBoxContainer or HBoxContainer in a ScrollContainer. When I do so, the item I drag now are drawn behind the screen (or cut by the container’s border, something like that) when I drag them.

Do you guys know how to fix that?

Here is my hierarchy:

Video of the bug:

Thanks for your help !

`

You can work with the z-index of nodes.
Nodes on a higher z-index are always drawn above nodes with a lower z-index

1 Like

Sorry I should have been more precise. I know about z_index but for some reason there’s something going on with ScrollContainer that I don’t understand in terms of z_index.

Changing z_index does not seem to solve the issue.
In this hierarchy, for example :

I tried to put

  • DragAndDropItem z_index at 100
  • DragAndDropSlot at 90
  • FoodContainer at 80
  • ScrollContainer at 70

It does not change anything.
Is there a something I should know about the way things are drawn when a control node is placed inside a VBoxContainer, and the VBoxContainer inside a ScrollContainer ?

I feel like the issue is based on a behavior of certain nodes, like, apparently, ScrollContainer (though I might be completely wrong).

What is weird do me is that if you look at the video, it seem to be drawn under the actual “screen” (I don’t know how to call it, the default grey frame of godot)… Like… why?

EDIT: Apparently I can solve the issue by checking visibility → top_level
I don’t know like this solution, though… Because now my item will appear somewhere else for a few frame and go back to my mouse (they will travel there)…
I’d like to have an explanation if someone is interested in giving me one, I love to learn about that stuff.

Yeah sorry didnt fully watch your video. The scrollcontainer has a property called “clip_contents”, which i guess is what makes the node disappear when it leaves the scrollcontainer, because its still considered as a child of the scroll container.

You can try to set this value to false and see if anything changes

1 Like

How do you set the drag preview? I tried the following (in my version of the DragAndDropSlot node) and was unable to recreate your problem.

func _get_drag_data(at_position: Vector2) -> Variant:
	set_drag_preview(self.duplicate())
	return {"data": true}

Can you share your project, so that it can be investigated properly?

1 Like

Thanks a lot! That was the source of the issue.
Thank you for your help :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.