_on_body_entered(body), body is null

Godot Version

func _on_body_entered(body):
	if body != null:
		body.get_node().health -= damage

Question

I have a system where when a collision occurs with an enemy, the health variable from the script of the enemy node is changed. The body is null. I made sure the mask and layer of bodies were correct, collisions were not disabled, signals were there, and other things. Is it a bug or is other any way to fix this?

Can you provide some info about your player and enemy setup? Also you might want to use an Area2d or 3d for that. I used it to detect what the player interacted with. Here was my implementation of it.

func _on_area_2d_body_entered(body : Node):
		mob_name = body.name
		if mob_name[0] == "g":
			emit_signal("score_increase", mob_name)
		if mob_name[0] == "b":
			emit_signal("score_decrease", mob_name)
		if mob_name[0] == "m":
			emit_signal("meteor_hit")

Thanks for the suggestion! Turns out that while creating the signal, the name of the function got changed somehow, I reconnected the signal and it works now.

Great to hear!