Skip to content

Commit

Permalink
[Physics] Fix reattach logic where component hasn't been attached yet (
Browse files Browse the repository at this point in the history
…#2465)

Co-authored-by: Basewq <[email protected]>
  • Loading branch information
Basewq and Basewq authored Sep 24, 2024
1 parent 2829889 commit 90522b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions sources/engine/Stride.Physics/Engine/PhysicsComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ internal void Attach(PhysicsProcessor.AssociatedData data)
/// </summary>
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)
Expand Down

0 comments on commit 90522b7

Please sign in to comment.