I have a simple window in Godot and a separate item outside this window. My goal is to drag and drop the item into the window.

I wrote two solutions: -The first method removed the item when it collides with the window and instantiates it inside the window as new object of the same type. -My alternate method re-parents the item node to the window.

Both work, and require very little code, but what is the better standard of practice in game development when it comes to this type "add item" system? Which solution is better for performance in the long run if I have multiple items that I am adding to the window?

I would use whichever works best for you and your project. Both methods have their pros and cons, and ultimately as long as you know how the system works and are fine working with it, then that's what matters.

From a performance perspective, I believe re-parenting nodes is slightly more performance friendly since it avoids the creation and deletion of data, but I would suggest running tests/benchmarks if you are wanting to know for sure.

Hi! Thank you for the answer, but I ended up completely scrapping my above methods. Yes it worked but I used KinematicBody2D for drag and drop combined with listeners and Area2d to add and remove items from my window. This was too convoluted and brought about other bugs into the mix. Mixing in a collision system for drag and drop was definitely not the answer on my part.

I followed this answer to reimplement drag, drop, item addition/removal from a window:

https://godotengine.org/qa/45323/drag-&-drop-issue

I now use the get_drag_data(), can_drop_data() and drop_data() virtual methods with Panels and Control nodes. It works like a charm.

Update: I answered the issue the above user was having on https://godotengine.org/qa/45323/drag-&-drop-issue, because I had a similar problem if anyone wants to dive deeper into the Godot drag & drop functionality.

2 years later