What happens is that I'm instancing a node as a child of another one through code using add_child. This is part of my inventory system, as the instanced node appears when getting an item. In order to instance the node I'm using the following function:
func ObjectToInventory(slot, item_name, texture_to_load):
slot.add_child(InventoryItemInstance)
slot.get_node("Item1").name = item_name
slot.get_node(item_name).ItemTexture = load(texture_to_load)
slot.get_node(item_name).texture_normal = load(texture_to_load)
ObjectToInventory(item_slots, "LEDTubeLight", "res://Textures/UI/InventoryImages/LEDTubeLight.png")
(InventoryItemInstance is the node I want to instance, which was defined before:
var InventoryItemScene = preload("res://Scenes/Assets/UI/InventoryItem.tscn")
var InventoryItemInstance = InventoryItemScene.instance()
This part of the code works perfectly, the problem is that the node is a button, and it doesn't seem to work when instancing it through code. The issue is not from the node itself, as I tried adding it through the editor, and it worked.
I also checked the remote tab, and the node was instanced correctly.
Before getting the item:

After getting the item:

I used isinstancevalid() to check if the node was instanced correctly, by printing something if it's valid. When I add the node from the editor, the instance is valid, but when it's added through code, it doesn't seem to be, as nothing is printed.
Any help would be appreciated