0 votes

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 areashapeentered()
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?

in Engine by (48 points)

1 Answer

+1 vote

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"):
by (1,193 points)

yah thats what i do

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

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

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:
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.