Modify allocation process of the PhysicalBoneSimulator in Skeleton3D

This commit is contained in:
Silc Lizard (Tokage) Renew 2024-04-25 03:08:49 +09:00
parent b9e022302a
commit 4900dddb88
2 changed files with 5 additions and 12 deletions

View file

@ -271,16 +271,15 @@ void Skeleton3D::_update_process_order() {
#ifndef DISABLE_DEPRECATED #ifndef DISABLE_DEPRECATED
void Skeleton3D::setup_simulator() { void Skeleton3D::setup_simulator() {
if (simulator && simulator->get_parent() == this) {
remove_child(simulator);
simulator->queue_free();
}
PhysicalBoneSimulator3D *sim = memnew(PhysicalBoneSimulator3D); PhysicalBoneSimulator3D *sim = memnew(PhysicalBoneSimulator3D);
simulator = sim; simulator = sim;
sim->is_compat = true; sim->is_compat = true;
sim->set_active(false); // Don't run unneeded process. sim->set_active(false); // Don't run unneeded process.
add_child(sim); add_child(simulator);
}
void Skeleton3D::remove_simulator() {
remove_child(simulator);
memdelete(simulator);
} }
#endif // _DISABLE_DEPRECATED #endif // _DISABLE_DEPRECATED
@ -294,11 +293,6 @@ void Skeleton3D::_notification(int p_what) {
setup_simulator(); setup_simulator();
#endif // _DISABLE_DEPRECATED #endif // _DISABLE_DEPRECATED
} break; } break;
#ifndef DISABLE_DEPRECATED
case NOTIFICATION_EXIT_TREE: {
remove_simulator();
} break;
#endif // _DISABLE_DEPRECATED
case NOTIFICATION_UPDATE_SKELETON: { case NOTIFICATION_UPDATE_SKELETON: {
// Update bone transforms to apply unprocessed poses. // Update bone transforms to apply unprocessed poses.
force_update_all_dirty_bones(); force_update_all_dirty_bones();

View file

@ -69,7 +69,6 @@ class Skeleton3D : public Node3D {
#ifndef DISABLE_DEPRECATED #ifndef DISABLE_DEPRECATED
Node *simulator = nullptr; Node *simulator = nullptr;
void setup_simulator(); void setup_simulator();
void remove_simulator();
#endif // _DISABLE_DEPRECATED #endif // _DISABLE_DEPRECATED
public: public: