diff --git a/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs b/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs index adf2104255..24a200791d 100644 --- a/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs +++ b/sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs @@ -119,7 +119,7 @@ public override ColliderShape ColliderShape if (InternalRigidBody == null) { - if (!attachInProgress) + if (Data != null && !attachInProgress) { //When setting ColliderShape, setup could have been previously skipped (eg when PhysicsComponent is created using GetOrCreate) ReAttach(); diff --git a/sources/engine/Stride.Physics/Engine/PhysicsComponent.cs b/sources/engine/Stride.Physics/Engine/PhysicsComponent.cs index 38accae8ce..df48af9495 100644 --- a/sources/engine/Stride.Physics/Engine/PhysicsComponent.cs +++ b/sources/engine/Stride.Physics/Engine/PhysicsComponent.cs @@ -698,6 +698,10 @@ internal void Attach(PhysicsProcessor.AssociatedData data) /// internal void ReAttach() { + if (Data == null) + { + throw new InvalidOperationException("PhysicsComponent has not been attached yet."); + } //TODO: Could consider fully detaching and then rebuilding, but ideally this would cause null refs on Rigidbody OnDetach calls //Shouldnt call detach, because at this point the user has added new components and this runs as a check to rebuild as needed. //Entire wipes to rebuild causes loss in the data that the user has just added (and is slower)