Copy of script is trying to read nodes of original script

Godot Version

4.3-stable

Question

I recently made an inventory system for a project I’m working on. I wanted to make a copy of the system for use as a seperate inventory for a container you can open. (i.e. a crate or barrel with goodies inside.) This works when I haven’t messed with the child/parent structure of the system. The reason I changed it around is due to being unable to properly anchor the ui elements to the top right corner of the screen. The problem I’ve run into is the copy of my inventory is trying to reference nodes from the original despite me renaming and re-referencing nodes in the copy.

CODE:
class_name ContainerInventory
extends Node2D

@onready var slot_scene = preload("res://Inventory/slot.tscn")
@onready var grid_container = $"../loot_MarginContainer/VBoxContainer/ScrollContainer/GridContainer"
@onready var item_scene = preload("res://Inventory/item.tscn")
@onready var scroll_container = $"../loot_MarginContainer/VBoxContainer/ScrollContainer"
@onready var col_count = grid_container.Columns
. . .

image

Any advice would be appreciated.

Do you mean that the copied script is trying to access nodes from your original scene even after modifying it? Make sure that you have assigned the correct script to the correct node.

It’d be better if you use @export var grid_container:GridContainer instead and assign it in the editor. That way you’d not need to copy/paste the script (as long as the implementation of the script is generic enough to cover both of your cases) and avoid duplication

I ended up figuring out that when copying the script it switched the original for the copy on my player.

In regards to the second part, I’ll have to see if that works. If I can cut down on making/duplicating scripts then that’d be great.