Instantiated instance does not have script

Godot Version

4.2.1

Question

I created a scene as PackedScene and loaded it from a script.
The scene Arrow.tscn has a script on the root, but the instantiated object(arrow) does not have that script.

Here is a part of my codes.

[Gameplay.gd]

...
arrow_scene = preload("res://Scenes/Arrow.tscn")

# arrow's class is Node2D and I want Arrow class as a result
var arrow = arrow_scene.instantiate()
...
[Arrow.gd]

extends Node2D

class_name Arrow

var speed
var aim

func _init(given_tag):
	speed = 50
...

You can’t use the constructor _init()with required parameters because instantiate() will fail then. It’s explained in the Object._init() documentation.

3 Likes

Oh, you’re right!
It works after I remove _init().
Thank you!