Godot Version
4.2.2.stable
Question
I am making an inventory system, where UIInventory
class is referencing UIDraggedItemRepresentation
class. The following is the relevant portions of the UIInventory
class:
extends Control
class_name UIInventory
@export_group("References")
# Other variables here
@export var dragged_item_representation: UIDraggedItemRepresentation
# Some other stuff
func _process(_delta):
if inventory_open:
if dragged_from_item == null:
if Input.is_action_just_pressed("primary"):
var container_over := get_container_over(get_global_mouse_position())
if container_over:
var item_over := container_over.get_item_representation_over(get_global_mouse_position())
if item_over:
dragged_from_item = item_over
dragged_item_representation.begin_dragging(item_over.global_position, item_over.container, item_over.item_index)
else:
# the rest of the code
The begin_dragging()
function is properly defined in the UIDraggedItemRepresentation
, I am certain of that. I have set the dragged_item_representation from the inspector, but I keep getting the goddamn
Invalid call. Nonexistent function 'begin_dragging' in base 'Nil'.
error every single time for no reason. The dragged_item_representation resets to null just before calling the dragged_item_representation.begin_dragging()
function for some godforsaken reason that is far beyond me to comprehend. The same issue happens when I get the node directly with get_node
like so:
get_node("Item Representation").begin_dragging(item_over.global_position, item_over.container, item_over.item_index)
And yes, that node is the direct child of the UIInventory node.
I have encountered a similar problem recently in the same project, that time with an Array. I think that this might be an internal godot interpreter error. Both times happened after I did some code refactoring, specifically utilizing the “Replace in Files” feature. I would report this as a bug, but I want to make sure I am not missing anything obvious like I usually do.