Help with duplicating objects

So I have been trying to create a projectile that spawns every half a second however, for some reason it can’t duplicate giving me the error “cannot call method instantiate on a null object” however I do have an object named book which is a packed scene, so what am I doing wrong.

@export var book: PackedScene;

var dup
var a = 0

func _process(delta: float) -> void:
	a += 1
	if a > 30:
		var dup = book.instantiate();
		add_child(dup,true);
		a = 0

Did you assign the exported variable in the inspector? The error states it is unassigned.

wdy mean? where do you assign that

@export allows you to set the variable’s value from the editor’s Inspector tab. Click on your node and set the property, otherwise it’s null

2 Likes

thanks, now I’ll deal with the rest on my own.

And just to add some opinion, you have declared var dup twice, inside and outside _func process maybe that gives you trouble with the “null” object.

You should try to use the declaration(if is really needed) that is inside your if condition. Maybe you won’t need the one out of _process.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.