hi all, trying to set up a simple inventory system with drag and drop. right now im currently having troubles with dragging/swapping items between slots. attached are my inventory and slot scenes, and my drag and drop code is located in a script attached to inv_slot. Here is my current setup for drag and drop:
func _get_drag_data(at_position: Vector2) -> Variant:
if !item_data:
return
var preview = duplicate()
var c = Control.new()
c.add_child(preview)
preview.position -= Vector2(20,20)
preview.self_modulate = Color.TRANSPARENT
c.modulate = Color(c.modulate, 0.5)
set_drag_preview(c)
return {"slot" : self, "item_data" : self.item_data}
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
#placeholder
return true
func _drop_data(at_position: Vector2, data: Variant) -> void:
if typeof(data) != TYPE_DICTIONARY:
return
var source_slot = data["slot"]
var source_item = data["item_data"]
if !item_data:
item_data = source_item
source_slot.item_data = null
else:
var temp = item_data
item_data = source_item
source_slot.item_data = temp
$"../../..".update_slots()
i think ive narrowed down the problem to something going on with _drop_data, as the first two functions return their data properly
its only when its dropped onto a slot that nothing seems to transfer. Also attached are relevant .gd scripts.