Check if body is a scene

Godot Version



I want to check if a body is a certain scene after i get collisions

func _on_despawn_box_body_entered(body):
	if body == DESIRED_SCENE:

What would i pu tfor the DESIRED_SCENE var
here is what the scene looks like

Well, scenes are nodes. Nodes have a “name” property which i believe is their name in the scene tree in the editor. Could be wrong.

May not be the best way to handle it though

Also, i believe (but have never used) that all tree items have meta data. So you could use that as well…

You could use groups.

  1. So put the body node in a certain group, like "despawns", following these steps: Groups — Godot Engine (stable) documentation in English

  2. Then when it enters the despawn box body, you can check if the body that is passed along as parameter to the function is in the right group.

if body.is_in_group("despawns"):
   # Rest of code

Here is some documentation that might help: Groups — Godot Engine (stable) documentation in English


can one scene be part of multiple groups?

Yes, one node can be part of multiple groups.


thanks this is gonna change how i make games in godot

1 Like

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