Godot Version
4.2.2
Question
Two extremely simple scripts and one problem
FIRST SCRIPT (class_name Projectile)
just add print_something() method
extends RigidBody3D
class_name Projectile
func _ready():
pass
func _process(delta):
pass
func print_something(): #THIS METHOD I WAN TO CALL
print("print_something")
SECOND SCRIPT
instantiae Projectile scene and call print_something()
extends StaticBody3D
@export var projectile_count = 4
@export var radius = 2
@onready var projectile_scene = load("res://scenes/environment/projectile.tscn")
func _ready():
pass
func _process(delta):
pass
func _on_area_body_entered(body):
for i in range(projectile_count):
var instance = projectile_scene.instantiate()
var projectile_instance = instance as Projectile
instance.print_something()
#Invalid call. Nonexistent function 'print_something' in base 'RigidBody3D'.
projectile_instance.print_something()
# Invalid call. Nonexistent function 'print_something' in base 'Nil'.
pass
why i can’t call print_something() method after instantiation? i didn’t get it
Error for Instance
#Invalid call. Nonexistent function ‘print_something’ in base ‘RigidBody3D’
Error for Instance as Projectile
#Invalid call. Nonexistent function ‘print_something’ in base ‘Nil’