Godot Version
3.5.3
Question
Hi, Im quite new to Godot and have been following this tutorial (which I’m sure many of you are familiar with) online to make an inventory: https://www.youtube.com/watch?v=ssYqIQQPt7A&t=934s&ab_channel=Arkeve
However, under my Item 2D node, it is not recognising the TextureRect and Label as children. I have the hierarchy set up correctly with the script attached to the Item node and both the Label and the TextureRect are children of this node. I have modified the script from the video to try and figure out the problem, which occurs whenever I try to open the inventory:
extends Node2D
onready var item_texture = $TextureRect
var item_name
var item_quantity
var prisma2 = null
var being_obtained = false
func _ready():
item_name = "AUG_TomCat"
if item_texture:
item_texture.texture = load("res://Sprites/Prisma 2/" + item_name + ".png")
var stack_size = int(JsonData.item_data[item_name]["StackSize"])
item_quantity = randi() % stack_size + 1
if stack_size == 1:
$Label.visible = false
else:
$Label.text = String(item_quantity)
else:
print("TextureRect node does not exist!")
func set_item(nm, qt):
item_name = nm
item_quantity = qt
if item_texture:
#
item_texture.texture = load("res://Sprites/Prisma 2/" + item_name + ".png")
var stack_size = int(JsonData.item_data[item_name]["StackSize"])
if stack_size == 1:
$Label.visible = false
else:
$Label.visible = true
$Label.text = String(item_quantity)
else:
print("TextureRect node does not exist!")
func add_item_quantity(amount_to_add):
item_quantity += amount_to_add
$Label.text = String(item_quantity)
func decrease_item_quantity(amount_to_remove):
item_quantity -= amount_to_remove
$Label.text = String(item_quantity)
Whenever I open the inventory it prints “TextureRect node does not exist!” twice.
This is what the error looks like in the debugger:
E 0:00:01.666 get_node: (Node not found: “TextureRect” (relative to “/root/Inventory/GridContainer/Slot1/@@2”).)
<C++ Error> Method failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1476 @ get_node()
Item.gd:3 @ _ready()
Slot.gd:33 @ initialise_item()
Inventory.gd:16 @ initialize_inventory()
Inventory.gd:10 @ _ready()
I will appreciate any help that you guys can give me