is not a subclass of the expected argument class." can you explain to me what's is means?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By szccornish

" Invalid type in function ‘add_child’ in base ‘Node2D (tes.gd)’. The Object-derived class of argument 1 (PackedScene) is not a subclass of the expected argument class."
can you explain to me what’s is means?

here my code :

extends Node2D

onready var tex = preload(“res://TSCN/Item_InRealWorld.tscn”)

var follow := false

func _ready():
. add_child(tex)

func _on_Button_pressed():
. follow = true
. pass # Replace with function body.

func _process(delta):
. if follow:
… tex.position = get_global_mouse_position()

:bust_in_silhouette: Reply From: RoniPerson

When you load a scene using preload you get an instance of the type PackedScene.
But to add a child you need something that inherits from Node2D. Therefore you have to create an instance of the loaded scene. Use tex.instance() for this.

Don’t use

 addchild(tex)

but

addchild(tex.instance())