Checking if a node's script has a method

I wondered if there were a simple check if the area type passed to the callback function _on_area_entered(area) has the die() function and discovered after a fair bit if searching this works:

func _on_area_entered(area):
	queue_free()
		
	if (area.has_method("die")):
		area.die()

However, in another post it’s mentioned that the layers approach is probably more efficient so only posting this out of interest. There are often numerous ways of achieving the same goal.

The above code works but has a drawback that there could be other nodes of the same type added later on with a die() method and we might not want their die() methods triggered.

4 Likes

nice one, ill pop that in the toolbelt , brill share :+1:

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

Privacy & Terms