Preload file does not exist error. but the file clearly exists

Godot Version

4.1.1

Question

I’m not sure why this is happening, It doesn’t register for any path

That’s not how preload works, the argument is a path to a file not a reference to a node in the scene tree.

if you want to access the node and therefore its children (which I think is what you are going to do) you do not need the preload.

Just:

@onready var items = $NinePatchRect

thanks, I’m just trying to instantiate a node and make it a child of NinePatchRect

If you want to instantiate a built-in node (e.g. Sprite2D), you’d do:

var Inst = Sprite2D.new()
$NinePatchRect.add_child(Inst)

If you want to instantiate a custom scene, you need to create it first, save it somewhere and then reference it by the path you stored it under, like so:

var Inst = preload("<file_path>").instantiate()
$NinePatchRect.add_child(Inst)
1 Like

ok! I’ll try that!

extends Control
@onready var items = $NinePatchRect/GridContainer/Panel
var shoparray_1

func _ready():
	shoparray_1=[["Milk",50],["Coffee",75],2]
	update(shoparray_1)

func update(x):
	for i in shoparray_1[-1]:
		var Inst = preload("res://scenes/shopSlotui.tscn").instantiate()
		$NinePatchRect/GridContainer.add_child(Inst)
		Inst.position=Vector2(100.0, 100.0)

this is what I’ve wrote, and it works!. it adds the node to the scene but I can’t change the instance’s position. and It doesn’t show any error

this is what I’ve wrote, and it works!. it adds the node to the scene but I can’t change the instance’s position. and It doesn’t show any error

I think you misunderstand how containers works, you can’t directly control a container child position and size, is exactly the function of container control that automaticly.

From the Container documentation:

When a Container-derived node is used, all children Control nodes give up their own positioning ability. This means the Container will control their positioning and any attempt to manually alter these nodes will be either ignored or invalidated the next time their parent is resized.

Likewise, when a Container derived node is resized, all its children will be re-positioned according to it, with a behavior based on the type of container used

3 Likes