@@ -83,7 +83,7 @@ void JoltArea3D::_add_to_space() {
8383
8484 jolt_settings->SetShape (jolt_shape);
8585
86- JPH::Body *new_jolt_body = space->add_rigid_body (*this , *jolt_settings);
86+ JPH::Body *new_jolt_body = space->add_rigid_body (*this , *jolt_settings, _should_sleep () );
8787 if (new_jolt_body == nullptr ) {
8888 return ;
8989 }
@@ -275,6 +275,18 @@ void JoltArea3D::_force_areas_exited(bool p_remove) {
275275 }
276276}
277277
278+ void JoltArea3D::_update_sleeping () {
279+ if (space == nullptr ) {
280+ return ;
281+ }
282+
283+ if (_should_sleep ()) {
284+ space->get_body_iface ().DeactivateBody (jolt_body->GetID ());
285+ } else {
286+ space->get_body_iface ().ActivateBody (jolt_body->GetID ());
287+ }
288+ }
289+
278290void JoltArea3D::_update_group_filter () {
279291 if (!in_space ()) {
280292 return ;
@@ -316,19 +328,23 @@ void JoltArea3D::_events_changed() {
316328}
317329
318330void JoltArea3D::_body_monitoring_changed () {
319- if (has_body_monitor_callback ()) {
331+ if (is_monitoring_bodies ()) {
320332 _force_bodies_entered ();
321333 } else {
322334 _force_bodies_exited (false );
323335 }
336+
337+ _update_sleeping ();
324338}
325339
326340void JoltArea3D::_area_monitoring_changed () {
327- if (has_area_monitor_callback ()) {
341+ if (is_monitoring_areas ()) {
328342 _force_areas_entered ();
329343 } else {
330344 _force_areas_exited (false );
331345 }
346+
347+ _update_sleeping ();
332348}
333349
334350void JoltArea3D::_monitorable_changed () {
@@ -513,15 +529,15 @@ void JoltArea3D::set_monitorable(bool p_monitorable) {
513529}
514530
515531bool JoltArea3D::can_monitor (const JoltBody3D &p_other) const {
516- return (collision_mask & p_other.get_collision_layer ()) != 0 ;
532+ return is_monitoring_bodies () && (collision_mask & p_other.get_collision_layer ()) != 0 ;
517533}
518534
519535bool JoltArea3D::can_monitor (const JoltSoftBody3D &p_other) const {
520536 return false ;
521537}
522538
523539bool JoltArea3D::can_monitor (const JoltArea3D &p_other) const {
524- return p_other.is_monitorable () && (collision_mask & p_other.get_collision_layer ()) != 0 ;
540+ return is_monitoring_areas () && p_other.is_monitorable () && (collision_mask & p_other.get_collision_layer ()) != 0 ;
525541}
526542
527543bool JoltArea3D::can_interact_with (const JoltBody3D &p_other) const {
0 commit comments