what is preferred way to interact with inventory?

Godot Version

4.6.3

how should i interact with my inventory and also please if there is some recomendation on game structure, give it to me because im lost!

i started creating survival game and made inventory system from tutorial, but made it fit my needs. It contains inventory script with functions like (add_item, remove_item… so on). I created “gameManager” that contains the logic of collecting items, and from there i tried to call the “add_item” function that takes in "ItemData” but it doesnt work. error that it shows tells me that it cant recognice or find the “Inventory (node) that contains the script and that i call like this “@onready var inventory: Inventory = $“../Player/Inventory””

extends Node

@onready var inventory: Inventory = $"../Player/Inventory"
@export var WOOD: ItemData

var wood_scene = preload("res://Items/collectables/scenes/wood.tscn")
var item_dict : Dictionary = {0: WOOD}

func _ready() -> void:
	var wood_instance = wood_scene.instantiate()
	add_child(wood_instance)

func _add_to_inv(item : int):
	var success = inventory.add_item(item_dict[item])
	print(success)

func add_item (item: ItemData) -> bool: #this is from Inventory script
	var slot : ItemSlot = get_item_slot(item)
	if slot and slot.quantity < item.max_stack:
		slot.quantity += 1...

and error happens when i call the “_add_to_inv” function

Did you add your gameManager as a global? If so you need to remove the gameManager from your scene tree, autoloads will be automatically loaded when the game starts, having one in the scene tree means you will end up with two while the game runs.

You shouldn’t use paths with ../ whenever possible, if you only intend to have one player per-device (i.e. no local multiplayer) then you could make your inventory itself a global so long as you reset it between loading saves.

thanks. i fixed it by making inventory “global” like u suggested, now i have new problem but hopefully i will find the solution.

with good regards Me