I am struggling creating Exp like Vampire Survivors

Godot Version

4.2.2

Question

Total game dev newbie here! I am trying to set up an exp system, the same as Vampire Survivors where enemies drop exp gems. My problem is when I queue_free() / kill the enemy, it does not spawn (and or call the function to spawn) the gems that I instance in which I do in a function that I call on my bool is_dead being true (is_dead also calls queue_free(), to clarify). I am using GD Script btw. Thanks in advance!

Can you show your code to spawn your gems? You have to instance the gems before you call queue_free() on your enemy

This is on my enemy script:

func summon_exp():
	var EXP = preload("res://Scenes/exp.tscn")
	var new_exp = EXP.instantiate()
	new_exp.position = position
	add_child(new_exp)


func _on_animated_sprite_2d_animation_finished():
	if is_dead:
		summon_exp()
		queue_free()

Since EXP is added as the child of the enemy, when the enemy is destroyed, the exp will be destroyed with it.
So you can try to put the exp on the parent of the enemy or somewhere else.

get_parent().add_child(new_exp)

Awesome, this worked for me. Seems I need to spend some more time reading the documentation… Anyhow thanks for the help! I was stuck on this for an embarrassingly long time

As a tip, if you don’t want to think about structure and just want to add it to the current scene, you can use the

  get_tree().current_scene.add_child()

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