Attempt to call function 'instantiate' in base 'null instance' on a null instance

Godot Version

v4.2.1.stable.official [b09f793f5]

context

im following heartbeast’s action rpg tutorial on godot 4.2 . obviously this came with problems such as things being different but i can usually find a solution from googling and reading comments. but this time i cant find a solution anywhere, nobody has my exact problem.

Question

i am currently on part 15 of the tutorial, and while making changes to the effects code (also following the tutorial) i get this error Attempt to call function 'instantiate' in base 'null instance' on a null instance.
why does this happen and how do i fix it?

func grass_effect():
	var GrassEffect = load("res://scenes/effects/grassdie.tscn")
	var grassEffect = GrassEffect.instantiate()
	var world = get_tree().current_scene
	world.add_child(grassEffect)
	grassEffect.global_position = global_position
	grassEffect.rotation = randf_range(-0.5, 0.5)
	grassEffect.skew = randf_range(-0.5, 0.5)
	


func _on_hurtbox_area_entered(area):
	grass_effect()
	queue_free()

note: some things aren’t named 1:1 to the tutorials in order to give it my own personality to it, and that hasn’t broken anything so far.

GrassEffect is null. Make sure the file path in load() is correct, no misspellings or anything.
edit: if it’s correct and still doesn’t work, try using preload() instead of load

1 Like

worked! thank you! what a silly oversight.

1 Like

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