diff --git a/SDK/include/NDK/Systems/PhysicsSystem3D.hpp b/SDK/include/NDK/Systems/PhysicsSystem3D.hpp index 86ee0aa65..f1164fd0d 100644 --- a/SDK/include/NDK/Systems/PhysicsSystem3D.hpp +++ b/SDK/include/NDK/Systems/PhysicsSystem3D.hpp @@ -27,6 +27,7 @@ namespace Ndk static SystemIndex systemIndex; private: + void CreatePhysWorld() const; void OnEntityValidation(Entity* entity, bool justAdded) override; void OnUpdate(float elapsedTime) override; diff --git a/SDK/include/NDK/Systems/PhysicsSystem3D.inl b/SDK/include/NDK/Systems/PhysicsSystem3D.inl index 9a8d3ba8c..b6b1cbb03 100644 --- a/SDK/include/NDK/Systems/PhysicsSystem3D.inl +++ b/SDK/include/NDK/Systems/PhysicsSystem3D.inl @@ -11,6 +11,9 @@ namespace Ndk inline Nz::PhysWorld3D& PhysicsSystem3D::GetWorld() { + if (!m_world) + CreatePhysWorld(); + return *m_world; } @@ -21,6 +24,9 @@ namespace Ndk inline const Nz::PhysWorld3D& PhysicsSystem3D::GetWorld() const { + if (!m_world) + CreatePhysWorld(); + return *m_world; } } diff --git a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp index 7f41d02c8..f92e8a92a 100644 --- a/SDK/src/NDK/Systems/PhysicsSystem3D.cpp +++ b/SDK/src/NDK/Systems/PhysicsSystem3D.cpp @@ -41,6 +41,13 @@ namespace Ndk { } + void PhysicsSystem::CreatePhysWorld() const + { + NazaraAssert(!m_world, "Physics world should not be created twice"); + + m_world = std::make_unique(); + } + /*! * \brief Operation to perform when entity is validated for the system * @@ -62,7 +69,7 @@ namespace Ndk entities.Insert(entity); if (!m_world) - m_world = std::make_unique(); + CreatePhysWorld(); } /*!