Skip to content

Commit 90522b7

Browse files
authored
[Physics] Fix reattach logic where component hasn't been attached yet (#2465)
Co-authored-by: Basewq <Basewq@users.noreply.github.com>
1 parent 2829889 commit 90522b7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

sources/engine/Stride.Physics/Elements/RigidbodyComponent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public override ColliderShape ColliderShape
119119

120120
if (InternalRigidBody == null)
121121
{
122-
if (!attachInProgress)
122+
if (Data != null && !attachInProgress)
123123
{
124124
//When setting ColliderShape, setup could have been previously skipped (eg when PhysicsComponent is created using GetOrCreate)
125125
ReAttach();

sources/engine/Stride.Physics/Engine/PhysicsComponent.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,10 @@ internal void Attach(PhysicsProcessor.AssociatedData data)
698698
/// </summary>
699699
internal void ReAttach()
700700
{
701+
if (Data == null)
702+
{
703+
throw new InvalidOperationException("PhysicsComponent has not been attached yet.");
704+
}
701705
//TODO: Could consider fully detaching and then rebuilding, but ideally this would cause null refs on Rigidbody OnDetach calls
702706
//Shouldnt call detach, because at this point the user has added new components and this runs as a check to rebuild as needed.
703707
//Entire wipes to rebuild causes loss in the data that the user has just added (and is slower)

0 commit comments

Comments
 (0)