Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area 2d in child of instantiated scene behaves differently #92135

Closed
DJMcMayhem opened this issue May 19, 2024 · 3 comments
Closed

Area 2d in child of instantiated scene behaves differently #92135

DJMcMayhem opened this issue May 19, 2024 · 3 comments

Comments

@DJMcMayhem
Copy link

Tested versions

Tested in 4.2.1, 4.2.2, and 4.3 dev6

System information

Godot v4.2.1.stable - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce GTX 1080 (NVIDIA; 31.0.15.3734) - AMD Ryzen 9 7900X 12-Core Processor (24 Threads)

Issue description

I have a very simple scene named "moving_area_2d". It just moves to the right slowly and prints a message if it enters another area2d. This scene hierarchy is just:

  • Node2d
    • Area2d
      • CollisionShape2d

In my main scene, I have only two nodes: An instance of moving_area_2d, and an area2d that is sitting in it's path. I connect the area2d's "area_entered" signal to a print message. So what I expect should happen is once the moving area collides with the static area, both areas print a message. Instead, only the moving area 2d prints anything. The static area 2d never has it's "area_entered" signal emitted. The strangest part is that if I recreate the project from scratch, then it works. So something about this existing project is "corrupted" or something?

Steps to reproduce

Run the attached MRP. Enable "visible collision shapes" to see the two rectangles. Only one line of debug output is printed, instead of two. Also attached is an essentially identical project that was created from scratch that does not exhibit the same bug.

Minimal reproduction project (MRP)

area 2d test.zip (Exhibits problem)
area2dbug.zip (Works correctly)

@cosparks
Copy link
Contributor

cosparks commented May 20, 2024

If you open area_2d_test's main.gd file in the script editor, you will see that your _on_area_2d_area_entered isn't connected to anything (no signal connected symbol). Then, if you look inmain.tscn, you will see that you are attempting to connect a function called _on_static_area_2d_area_entered to StaticArea2D's area_entered signal. If you change this line:

[connection signal="area_entered" from="StaticArea2D" to="." method="_on_static_area_2d_area_entered"]

To this:

[connection signal="area_entered" from="StaticArea2D" to="." method="_on_area_2d_area_entered"]

Then everything will work fine.

For reference, this is the green icon that you should see:
image

It is not there in area_2d_test.zip:
image

@cosparks
Copy link
Contributor

I honestly recommend just connecting signals through code so you don't run into problems like this.

@DJMcMayhem
Copy link
Author

Hey Cosparks. You're right, it seems that I made some mistakes as I was trying to pare this down to an MRP. I've found the real source of the issue in the original project, and it really has nothing to do with what I've detailed here, so I'm closing this out. This was really just user error, so it probably wasn't worth raising an issue over to begin with. Sorry about that :/

I really appreciate the help though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants