Weird error and trying to make a for loop add an array of nodes to a container

Godot Version

v4.2.2

Question

What does this error mean?

“Invalid type in function ‘add_child’ in base ‘HBoxContainer (scalemenu.gd)’. The Object-derived class of argument 1 (PackedScene) is not a subclass of the expected argument class”

Code:


SBC stores button nodes that can be pressed to instantiate objects. This code needs to add nodes to the container (SBC) when a function is run, and it needs to know what to add by checking an array (inventory, or invent)

You are appending a PackedScene into the invent array. Node.add_child() only accept nodes. You’ll need to instantiate() the PackedScene before adding it.

2 Likes

Oh got it, thanks : D

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