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

Fix get_contact_count sometimes being incorrect in _process #88019

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

mihe
Copy link
Contributor

@mihe mihe commented Feb 6, 2024

Fixes #88018.

This replaces the usage of body_get_direct_state in RigidBody*D.get_contact_count with a cached value that's populated as part of RigidBody*D._sync_body_state, similar to other states in the physics bodies, which prevents _process from accessing a yet-to-be-synced future contact count.

This also fixes the inability to use get_contact_count from _process when using the physics/*d/run_on_separate_thread project setting.

@mihe mihe requested review from a team as code owners February 6, 2024 13:39
@mihe mihe changed the title Fix contact count sometimes being incorrect in _process Fix get_contact_count sometimes being incorrect in _process Feb 6, 2024
@AThousandShips AThousandShips added this to the 4.x milestone Feb 6, 2024
@AThousandShips AThousandShips requested a review from a team February 6, 2024 13:46
@AThousandShips
Copy link
Member

I'm assuming no operations like move_and_collide or anything else can change the collision count? And that it's fully safe to just cache it

@mihe
Copy link
Contributor Author

mihe commented Feb 6, 2024

Yes, that's correct. Contact counts are solely generated/modified during the simulation step.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Feb 6, 2024
@akien-mga akien-mga merged commit ca733a4 into godotengine:master Feb 14, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

@mihe mihe deleted the wrong-contact-count branch February 19, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_contact_count yields different results from _process and _physics_process
3 participants