Can packed scenes just not insatiate themselves recursively or am I missing something?

Godot Version

4

Question

I’ve been trying to get my feet wet with godot 4 by making a simple clone of asteroids and I thought the easiest way to have the asteroids split is just have it insatiate itself twice over and delete the original for that effect. For the life of me I can not get this to work. What’s odd is the bullet code works just as expected I insatiate it and I can access all of its specific variables, its only the asteroid throwing some variation of can not find method or variable depending on what I use. More over the scene itself keeps throwing errors that the scene is either invalid or corrupt. Is this a bug or am I just doing something stupid?

Here is the spawn code

func Spawn_Asteroid(size, direction, speed):
	var ast = Ast.instantiate()
	get_tree().root.add_child(ast)
	ast.start(size,direction,speed)
	ast.global_position = global_position

Here is the code for start

func start(size, speed, direction):
	Size = size
	Direction = direction
	Speed = speed
	if Size == 3:
		Direction = randi_range(0, 359)
		Speed = randi_range(50,100)
	scale = Vector2.ONE * 0.5 * Size

and to prove I have Ast set

var Ast : PackedScene = preload("res://Objects/Asteroid/Asteroid.tscn")

With this code it keeps throwing Invalid call. Nonexistant function ‘start’ in base 'Area2D

The return type of instantiate() is going to be Node in this case, which does not contain a .start() function. When instantiating, you’ll want to cast it before calling functions from your class.

var ast = Ast.instantiate() as Asteroid

Tried that already it then throws the error: Invalid call. Nonexistent function ‘start’ in base ‘Nil’

Does your Asteroid have a class_name?
Casting to a nonexisiting class results in a null value. Nonexistent function ‘start’ in base ‘Nil’ says that ast is null. Nothing has been instantiated.

Having some more code to look at would be helpful and your node setup.

I ended up fixing it by delegating spawning to a manager node everything works as it should now and the asteroid scene stopped getting corrupted. After I finish this project I might go back and try to reproduce this to see if it was just a one off thing or if its a bug. As for those asking yes Asteroid does have a class_name set.