enable bGravityEnabled, bSimulatePhysics, and call WakeRigidBody on grab component's owning actor at BeginPlay() if bAffectPhysicsState is enabled

This commit is contained in:
Mamadou Babaei
2024-08-16 16:44:34 +02:00
parent 787ab5aa96
commit 058bc5a87c
3 changed files with 30 additions and 0 deletions
@@ -135,4 +135,29 @@ USGGrabComponent::FImpl::~FImpl() = default;
void USGGrabComponent::FImplDeleter::operator()(const FImpl* P) const
{
delete P;
}
void USGGrabComponent::BeginPlay()
{
Super::BeginPlay();
if (bAffectPhysicsState)
{
const AActor* OwnerActor{GetOwner()};
if (!ensureAlwaysMsgf(IsValid(OwnerActor), TEXT("Invalid OwnerActor!")))
{
return;
}
UPrimitiveComponent* ActorRootComponent{Cast<UPrimitiveComponent>(OwnerActor->GetRootComponent())};
if (!ensureAlwaysMsgf(IsValid(ActorRootComponent),
TEXT("RootComponent is not a valid UPrimativeComponent!")))
{
return;
}
ActorRootComponent->SetEnableGravity(true);
ActorRootComponent->SetSimulatePhysics(true);
ActorRootComponent->WakeRigidBody();
}
}
@@ -196,4 +196,7 @@ public:
{
bAffectPhysicsState = bInAffectPhysicsState;
}
public:
virtual void BeginPlay() override;
};