0 votes

" 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

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

func process(delta):
. if follow:
.. tex.position = get

Godot version 3.2.1
in Engine by (69 points)

1 Answer

+4 votes

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



by (336 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.