The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I don't know if this a bug or something but since today, an Area2D that I use so the character can interact with anything depending on the direction he's watching has been working weirdly. Today, I just made little changes that don't affect this Area2D. So here's the thing, when I want to interact with something it doesn't work. After testing with prints, I found out that the Area2D detects bodyentered and then bodyexited instantly after the first one, even does when the body stills on the Area2D collision shape making it unable to interact with it. Is this some bug or I need to check my code?

Edit: Forgot to mention that sometimes that I start the game it works has planned to do and other times does what I mentioned.

Godot version 3.2.3
in Engine by (65 points)

Definitely going to need more information haha. wanna show your script for the Area2D's interaction?

This has only happened to me when I have freed nodes from within an Area2D and it emits the body_exited signal.

The Area2D has not coded. But the player does about this and is basically this:

var object = null

func _body_entered(body):
if body.has_method("interact"):
  object = body

func _body_exited(body):
if body.has_method("interact"):
  object = null

1 Answer

0 votes

I myself has encountered something similar, but I'm not entirely sure if it's the same situation.

Basically, Let's look at this node I created:

>Player(KinematicBody2D)
  > CollisionShape2D
  > Sprite
  > Area2D
     >CollisionShape2D

The situation where I encountered this problem was when my Area2D's collisionshape was overlapping my KinematicBody2D's collisionshape and they were on the same Physics Layer and Mask. Thus, on initialization, Area2D's body entered/exited is triggered. But in your case, I'm not entirely sure.

So a quick debug would be:

func _body_entered(body):
  print(body.name)

func _body_exited(body):
  print(body.name)

Which should tell you which body is being detected.

by (378 points)

Using prints and if statements to see what's happening, I can confirm what is happening, when the Area2D enters the CollisionShape2D, the Area2D detects bodyentered and instantly bodyexiting with the body the no exiting really. I used if statements so the object will not be null until the exiting body is the same as the stored object, so yeah, I think is a bug or something.

Edit: Found out what happened, in the connect function I put "bodyentered" instead of "bodyexiting", but that's not all, I didn't modify that line since a lot of time ago, so It's weird that the Area2D worked as intended until now.

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 Frequently asked questions and 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 [email protected] with your username.