Godot 4: Drag and Drop data swap doesn’t work with custom resources

I’m currently in the process of making a screen that has ability slots, and it is up to the player to mix and match them and change the order at will. The Drag and Drop functionality worked just fine when it was one-way, but when I tried adding the process of actually swapping the data between the two nodes (should both have any), I keep running into errors.

I have a custom resource called Ability and the slots have a variable called “selected_ability” that takes these and uses it to set the textures and other information.

extends TextureRect
class_name AbilitySlot

@export var selected_ability: Ability

@onready var slot: AbilitySlot = $"."


func _process(_delta):
    if selected_ability:
        slot.texture = selected_ability.icon
    else:
        slot.texture = null
    
func _get_drag_data(_at_position):
    set_drag_preview(get_preview())
    global.origin_slot = self.get_name()
    global.origin_ability = self.selected_ability
    print(global.origin_slot)
    print(global.origin_ability)
    return slot.selected_ability
    
func get_preview():
    var preview_texture = TextureRect.new()
    if selected_ability:
        preview_texture.texture = slot.selected_ability.icon
        preview_texture.expand_mode = 1
        preview_texture.size = Vector2(64,64)
    var preview = Control.new()
    preview.add_child(preview_texture)
 
    return preview
    
func _can_drop_data(_at_position, data):
    global.target_slot = get_name()
    if selected_ability:
        global.target_ability = selected_ability
    else:
        global.target_ability = null
    print(global.target_slot)
    print(global.target_ability)
    return true

func _drop_data(_at_position, data):
    global.origin_slot.selected_ability = global.target_ability         < ERROR
    selected_ability = global.origin_ability

The program crashes at Line 45 (the second from the bottom) with the error “Invalid set index ‘selected_ability’ (on base: ‘StringName’) with value of type ‘Resource (Ability)’.”

If I comment the problematic line out, the program successfully copies the desired contents of the origin slot to the target slot, but the origin slot remains unchanged, so it acts as an infinite duplicate source. I know this because the abilities that slots set up successfully pass onto the next screen, it is only the swap that doesn’t work.

What would be the correct way to handle the origin slot if I want to switch data?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật