Errors in console, but func is working

Godot Version

4.2

Question

Hello, i got a lot of errors in my code.

"### Inventory_Slot.gd
extends Control

Scene-Tree Node references

@onready var icon = $InnerBorder/ItemIcon
@onready var quantity_label = $InnerBorder/ItemQuantity
@onready var details_panel = $DetailsPanel
@onready var item_name = $DetailsPanel/ItemName
@onready var item_type = $DetailsPanel/ItemType
@onready var item_effect = $DetailsPanel/ItemEffect
@onready var usage_panel = $UsagePanel
@onready var assign_button = $UsagePanel/AssignButton
@onready var outer_border = $OuterBorder

Signals

signal drag_start(slot)
signal drag_end()

Slot itemы

var item = null
var slot_index = -1
var is_assigned = false

func _ready():
# Отладочные сообщения для проверки наличия узлов
if has_node(“UsagePanel”):
print(“UsagePanel найден”)
else:
print(“UsagePanel не найден”)

if has_node("UsagePanel/AssignButton"):
	print("AssignButton найден")
else:
	print("AssignButton не найден")"

The problem is that i have errors Inventory_Slot.gd:9 @ _ready(): Node not found: “DetailsPanel/ItemType” (relative to “/root/InventorySlot”). for all onready functions, but when i start my game all slots are working well, no any doubds with UX

Do u know what it can be? No any red in my code, only in console errors.

UsagePanel не найден
AssignButton не найден
Item ready: RigidBody2D
UsagePanel найден
AssignButton найден

looks like problem that during start it cannot found it, and then after time it start to work.

As i understand you are new here as i was so use this ``` between your code to be easer, i mean before pasting your code.

Hey!

Your variable looks all nicely setup, but it could be an accession from somewhere else

Like an event callback that happens before _ready or those could be accessed by a child of InventorySlot in their own ready

Wish you luck!

Still cannot understand how to fix it, I tryied to use
func _ready():
await get_tree().process_frame

Are you using your Inventory_Slot script somewhere else other than that scene? Because it seems like you accidentally attached the Inventory_Slot.gd script to some other object and when that object loads it tries to find all those child nodes (that you do have in the Inventory_Slot scene) and fails for all of them.

try this:

func _ready():
  print("Inventory_Slot object name : " + name)

And tell me what you see on your console. Alternatively, check if one of those names belong to an object that is not an Inventory_Slot.

Also, are you instantiating the inventory_slots on your code? Could you share how you instantiate them?

"### Inventory_UI.gd

extends Control

Scene-Tree Node references

@onready var grid_container = $GridContainer

Drag/Drop

var dragged_slot = null

func _ready():
# Connect function to signal to update inventory UI
grid_container.columns = 5
get_viewport().connect(“size_changed”, Callable(self, “_on_viewport_size_changed”))
Global.inventory_updated.connect(_on_inventory_updated)
call_deferred(“_on_inventory_updated”)

Update inventory UI

func _on_inventory_updated():
print(“_on_inventory_updated called in Inventory_UI”)
# Clear existing slots
clear_grid_container()
print(“Grid container cleared”)
# Add slots for each inventory position
for item in Global.inventory:
print("Processing item: ", item)
var slot = Global.inventory_slot_scene.instantiate()

	if slot == null:
		print("Error: Failed to instantiate slot")
		continue
	
	slot.drag_start.connect(_on_drag_start)
	slot.drag_end.connect(_on_drag_end)
	
	grid_container.add_child(slot)
	print("Slot added to grid container")
	
	if item != null:
		slot.set_item(item)
		print("Setting item in slot: ", item)
	else:
		print("Setting slot to empty")
		slot.set_empty() 

Clear inventory UI grid

func clear_grid_container():
while grid_container.get_child_count() > 0:
var child = grid_container.get_child(0)
grid_container.remove_child(child)
child.queue_free()

Store dragged slot reference

func _on_drag_start(slot_control : Control):
dragged_slot = slot_control
print("Drag started fro slot: ", dragged_slot)

func _on_drag_end():
var target_slot = get_slot_under_mouse()
if target_slot and dragged_slot != target_slot:
drop_slot(dragged_slot, target_slot)
dragged_slot = null

Get the current mouse position in the grid_container’s coordinate system

func get_slot_under_mouse() → Control:
var mouse_position = get_global_mouse_position()
for slot in grid_container.get_children():
var slot_rect = Rect2(slot.global_position, slot.size)
if slot_rect.has_point(mouse_position):
return slot
return null

Find the index of a slot

func get_slot_index(slot: Control) → int:
for i in range(grid_container.get_child_count()):
if grid_container.get_child(i) == slot:
# Valid slot found
return i
# Invalid slot
return -1

Drop slots

func drop_slot(slot1: Control, slot2: Control):
var slot1_index = get_slot_index(slot1)
var slot2_index = get_slot_index(slot2)
if slot1_index == -1 or slot2_index == -1:
print(“Invalid slots found”)
return
else:
if Global.swap_inventory_items(slot1_index, slot2_index):
print("Drpping slot items: ", slot1, slot2_index)
_on_inventory_updated()

"

when i delete all script that fault is dissapeared,

print("Inventory_Slot object name : " + name)

Inventory_Slot object name : InventorySlot
Item ready: RigidBody2D
Player ready
Success: inventory_ui instantiated
_on_inventory_updated called in Inventory_UI
Grid container cleared
Processing item:
Inventory_Slot object name : Inventory_Slot
Slot added to grid container
Setting slot to empty
Processing item:
Inventory_Slot object name : @Control@11
Slot added to grid container
Setting slot to empty
Processing item:
Inventory_Slot object name : @Control@12
Slot added to grid container
Setting slot to empty
Processing item:

I’m pretty sure this object is the problem. Where is that object? What is it? is it important? can you delete it?
image

The rest of your Inventory_Slots instantiate after “Processing item:” but that first object seems out of place.
Also, the errors are telling you the problem is that object, named “InventorySlot” without the underscore. It’s the only one named like that.

1 Like

Omg bro i found the problem xddd, I had autoload o the script xdddd, bruh idk why i add it there but i wasted to much time)))) Ya sometimes better to sleep more)) Thx

2 Likes

Autoloads, when not specified otherwhise, instantiate a script just with an empty Node. This is why your script wasn’t finding those $DetailPanel childs… because that empty node had no childs.
Glad you found it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.