Skip to content

Conversation

xuhuisheng
Copy link
Contributor

@xuhuisheng xuhuisheng commented Oct 21, 2025

Issue Description

Because StaticBody2D cannot be set active and cannot be add to active_list. So the StaticBody2D wont trigger actively collision itself.

_FORCE_INLINE_ void wakeup() {
if ((!get_space()) || mode == PhysicsServer2D::BODY_MODE_STATIC || mode == PhysicsServer2D::BODY_MODE_KINEMATIC) {
return;
}
set_active(true);
}

if (active) {
if (mode == PhysicsServer2D::BODY_MODE_STATIC) {
// Static bodies can't be active.
active = false;
} else if (get_space()) {
get_space()->body_add_to_active_list(&active_list);
}

Please notice this PR is just a demo to fix relevant issue. I am not sure it is the correct solution. Maybe current behavior is expected.

Explaination

In PhysicsServer2D, it decides which body need be detected collision depends on get_active_body_list() and get_moved_area_list().

const SelfList<GodotBody2D>::List *body_list = &p_space->get_active_body_list();

const SelfList<GodotArea2D>::List &aml = p_space->get_moved_area_list();

If there is no active_list or moved_area, the collision detection wont execute.

When we changed layer or mask, it invoke parent class GodotCollisionBody2D. It is the parent class of GodotBody2D and GodotArea2D. Then GodotArea2D added itself to moved_area_list, so next iteration will detect collision. But GodotBody2D wont add static body to active_list, so it can only wait other body to trigger collision detection.

It looks like StaticBody2D wont participate with integrate_force or integrate_velocity, maybe only add it to active_list is safe. But still need test for confirming.

@xuhuisheng xuhuisheng requested a review from a team as a code owner October 21, 2025 10:50
@AThousandShips AThousandShips added bug topic:physics topic:2d cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release labels Oct 21, 2025
@AThousandShips AThousandShips added this to the 4.6 milestone Oct 21, 2025
@AThousandShips AThousandShips changed the title Fix Static Body2D unable to actively trigger collisions Fix StaticBody2D not triggering collisions when waking up Oct 21, 2025
@AThousandShips
Copy link
Member

Does this actually fix the case when changing the layers only? This seems to fix just waking up the body

@xuhuisheng xuhuisheng force-pushed the dev/wakeup_static branch 2 times, most recently from 088a840 to 829da14 Compare October 21, 2025 11:20
@xuhuisheng
Copy link
Contributor Author

@AThousandShips

As in description, current physics engine does not support active StaticBody2D. So we cannot add StaticBody2D to active_body_list, so only update StaticBody2D layer or mask won't trigger collision. That is the reason.

The straight way to fix this issue is allow StaticBody2D to be set active and added to active_body_list, then it can trigger collision by itself.

If we dont want fixing issue this way, maybe we need add additional logic for StaticBody2D.

@AThousandShips
Copy link
Member

No what I'm asking is:
Does this fix the problem where changing the collision layers and mask doesn't trigger these signals, does changing the layers wake bodies up regardless if they are sleeping or not? The bug report has nothing to do with changing active

@xuhuisheng
Copy link
Contributor Author

@AThousandShips

I can get your point, I will test for only triggering adding active_list without set active.

@AThousandShips
Copy link
Member

The test project from the issue should confirm if this solves it!

@xuhuisheng
Copy link
Contributor Author

xuhuisheng commented Oct 22, 2025

@AThousandShips

I tested only add StaticBody2D toactive_list, without active = true. It can still solve the issue. I think it is better.

wakeup.webm

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

Labels

bug cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release needs testing topic:physics topic:2d

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Toggling body collision layer/mask will not update overlapping areas

2 participants