0 votes

Hello.
I am making an inventory system for my game, but I got one issue: I need to get the UI Node (TextureRect) that is in a certain position.
For example, to swap items between the inventory, I drag one item to another slot, and then I release the mouse button. I should be able to get the node that is in the position of the mouse (only when it is released).
Note: I use a GridContainer
Is there any way that I can achieve this?

asked Apr 24 in Engine by SebSharper (59 points)

Perhaps you can get the mouse's local position relative to the GridContainer. Then have a function that calculates which square that is based on GridContainer's square size, and number of columns and rows?

Do you know the name of the function?

I was thinking this function, which you may be able to use as a standalone

get_local_mouse_position()

Or it might be something like:

$"GridContainer".get_local_mouse_position()

Here's some other mouse positions that may be of help:
https://docs.godotengine.org/en/3.2/classes/class_canvasitem.html

I would just try a few ways of getting the mouse position and print the result of those functions to the debug/output console until you get the position you want.

1 Answer

+1 vote

Control nodes have built-in drag and drop support.
You can see an implementation example in the Drag and Drop demo project.

answered Apr 25 by hammeron (144 points)
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.