deleting node with several part of the name

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wahyuadiramadan

ive a project that using auto instancing an object and its created area2d by default name, and othe instance name is @name@2,@name@3,@name@4

and i ve an bullet which is it going to delete its self and the object that is collided wit the bullet

im using function area_shape_entered()
and delete it with the name “name”

but it wont delete if in the scene there are more than one object
the function will delete the area with name “name”
but it wont work for other object with name “@name@2”/“@name@3”/“@name@4”

how godot detect that word “name” is in “@name@2” too?

:bust_in_silhouette: Reply From: rustyStriker

when an object enters Area and emits the on_body_entered(body) signal, you can just pick the body that entered, and use queue_free() on the body as follows:

 func on_body_enter(body):
      if body.name.contains("name"):
              body.queue_free()

yah thats what i do

Merlin1846 | 2020-03-13 15:36

im using area2d btw, so i try to modify and the code be like this:

if area.name.contains("name"):
   area.queue_free()

and the still error, its says invalid call. Noneexistent function “contains” in base “String”.

but it solve by this code:

if "name" in area.name:
    area.queue_free()

wahyuadiramadan | 2020-03-18 08:53