The problem that I’m having rn, is that the image for the item in the inventory slot is not showing up. I made a .tres file for the item (LemonPepperWings) and a .tres file for storing the players inventory (PlayerInvi).
Here’s the code for the scripts that I made:
Inventory.gd:
extends Resource
class_name Invi
@export var items: Array[InviItem]
InventoryItem.gd:
extends Resource
class_name InviItem
@export var name: String = ""
@export var texture: Texture2D
inventoryUI.gd:
extends Control
@onready var invi: Invi = preload("res://Player/UI/Inventory/PlayersInvi.tres")
@onready var slots: Array = $MarginContainer/VBoxContainer/GridContainer.get_children()
var is_open = false
var speler = AudioStreamPlayer.new();
func _ready():
update_slots()
close()
func update_slots():
for i in range(min(invi.items.size(), slots.size())):
slots[i].update(invi.items[i])
func _process(delta):
if Input.is_action_just_pressed("Inventory"):
if is_open:
close()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
self.add_child(speler);
speler.stream = load("res://Sounds/Inventory.wav");
speler.play();
else:
open()
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
self.add_child(speler);
speler.stream = load("res://Sounds/Inventory.wav");
speler.play();
func open():
self.visible = true
is_open = true
func close():
visible = false
is_open = false
Can you show screenshots of your scene structure and the setups of your .tres files? You can add a couple of print statements, e.g. here to see what’s printed (if anything)
I have tried it, it did output the word “item” eight times. However, while looking at this, I noticed that I was getting errors in the debug.
Here’s what they look like:
W 0:00:01:0362 The parameter “event” is never used in the function “_input()”. If this is intended, prefix it with an underscore: “_event”.
UNUSED_PARAMETER
flashlight.gd:5
W 0:00:01:0399 The parameter “delta” is never used in the function “_process()”. If this is intended, prefix it with an underscore: “_delta”.
UNUSED_PARAMETER
inventoryUI.gd:17
E 0:00:09:0997 inventoryUI.gd:22 @ _process(): Can’t add child ‘@AudioStreamPlayer@2’ to ‘Inventory UI’, already has a parent ‘Inventory UI’.
<C++ Error> Condition “p_child->data.parent” is true.
<C++ Source> scene/main/node.cpp:1568 @ add_child()
inventoryUI.gd:22 @ _process()
E 0:00:13:0048 inventoryUI.gd:28 @ _process(): Can’t add child ‘@AudioStreamPlayer@2’ to ‘Inventory UI’, already has a parent ‘Inventory UI’.
<C++ Error> Condition “p_child->data.parent” is true.
<C++ Source> scene/main/node.cpp:1568 @ add_child()
inventoryUI.gd:28 @ _process()
You’re loading the texture through code, so after starting the game go to the Remote tab, find your “inventory slots” in the scene tree and check if the correct texture is loaded in the texture property of the node. Something like here, but your tree will be much bigger:
Legit, this was a giant problem for me since I started working on the inventory system for so long now. I’m very grateful you helped me work this out. I can’t believe the error was such a simple solution, lesson learned I guess.