Hello!
I've been having this issue for almost a week and am really not sure what the problem is so would love some help.
In short;
I have an object that is a Node2D with a child that is an Area2D, which in turn has a Sprite and a CollisionShape2D.
The Area2D node has a Collision Layer by default that I change in runtime, for when I want to break the object in question so the player can fall through.
I've also made a simple Raycast from the Camera to a random position on the screen and when it hits the above object on the default Collision Layer, it should spawn an object, which it does.
The issue;
Whenever I start testing a level where I break the above object and change the Collision Layer to something the Raycast should ignore, it still hits and thus spawns a pickup in a location the player can't reach.
What I've tested so far;
I've been debugging this for almost a week and the object itself does change to the correct Collision Layer (checked through print and in Remote while running the game).
I changed so the Raycast can be delayed and when adding a silly amount, like 2 seconds, it can still hit an object that is broken with a different Collision Layer that it is supposed to ignore.
When I fire the Raycast, it reports the wrong layer in print from the broken object it hits, even though it has changed its Collision Layer when I check.
I also noticed that, if I completely remove the object in question, it still reports a hit and spawns a pickup.
Not having any object present will make the Raycast not hit anything and eventually give a Stack Overflow error, so its not hitting something else than this object.
As for the setup;
Area2D and its Collision Layer starts as the second option (Bit 1, value 2) and changes to the fourth option (Bit 3, value 8) when broken.
Raycast is set up as space_state.intersect_ray(ray_origin, ray_end, [self], 2, false, true)
I feel like I've tried so many things to debug this and I'm not sure anymore if it's something I'm missing or a mistake I made (more likely) or just a bug.
Am using Godot 3.2.3 stable official.
Any help is greatly appreciated, thanks!