Waking Physics Objects (Can No Longer Pickup The Object)

No Ideal what Happened here it was working fine and then I made those modifications from this video and suddenly I can no longer pick up the object even though it’s registering that it’s being picked up.

This is firing under UGrabber::GrabObject() but the object doesn’t seem to be attaching the the physics object for some reason.

// Called when the game starts
void UGrabber::BeginPlay()
{
	Super::BeginPlay();

	// ...
}


// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	// ...
	
	// Set The PhysicsHandle To A Location Offset In Front Of The Owning Actor
	UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();
	if (PhysicsHandle != nullptr)
	{
		return;
	}
	
	if (PhysicsHandle->GetGrabbedComponent() != nullptr)
	{
		const FVector TargetLocation = GetOwner()->GetActorLocation() + GetOwner()->GetActorForwardVector() * HoldDistance;
		PhysicsHandle->SetTargetLocationAndRotation(TargetLocation, GetOwner()->GetActorRotation());
	}
}

void UGrabber::GrabObject()
{
	// Find The Physics Handle And Return If It Isn't Found.
	UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();
	if (PhysicsHandle == nullptr)
	{
		return;
	}
	
	// Set The Start And End Location
	const FVector Start = GetComponentLocation();
	const FVector End = Start + GetForwardVector() * MaxGrabDistance;

	// Draw Debug Visuals
	DrawDebugLine(GetWorld(), Start, End, FColor::Red);
	DrawDebugSphere(GetWorld(), End, 10, 10, FColor::Blue, false, 5);

	// Create Collision Shape And Hit Result For Trace
	FCollisionShape Sphere = FCollisionShape::MakeSphere(GrabRadius);
	FHitResult HitResult;

	// Trace For the object
	bool HasHit = GetWorld()->SweepSingleByChannel(
		HitResult,
		Start,
		End,
		FQuat::Identity,
		ECC_GameTraceChannel1,
		Sphere);
	if (HasHit)
	{
		UPrimitiveComponent* HitComponent = HitResult.GetComponent();
		HitComponent->WakeAllRigidBodies();
		
		// If The Component Was Hit Attach It To The Physics Handle
		PhysicsHandle->GrabComponentAtLocationWithRotation(
			HitComponent,
			NAME_None,
			HitResult.ImpactPoint,
			GetOwner()->GetActorRotation()
			);
		UE_LOG(LogTemp, Display, TEXT("%s Was Picked Up!"), *HitComponent->GetName());
		
	}
	
}

void UGrabber::ReleaseObject()
{
	UPhysicsHandleComponent* PhysicsHandle = GetPhysicsHandle();
	if (PhysicsHandle == nullptr)
	{
		return;
	}
	if (PhysicsHandle->GetGrabbedComponent() != nullptr)
	{
		PhysicsHandle->GetGrabbedComponent()->WakeAllRigidBodies();
		PhysicsHandle->ReleaseComponent();
	}
	UE_LOG(LogTemp, Display, TEXT("Grabber Released!"));
}

UPhysicsHandleComponent* UGrabber::GetPhysicsHandle() const
{
	UPhysicsHandleComponent* PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
	if (PhysicsHandle == nullptr)
	{
		UE_LOG(LogTemp, Error, TEXT("Grabber Requires A UPhysicsHandleComponent."));
	}
	return PhysicsHandle;
}

If You look on the left when I’m holding the button down it’s firing that the object is being picked up and when I release it registers that it’s being released but if I hold the button down and move the skull stays where it is…
This was working before I modified the grabber and tick and added the release logic…I tried to undo what I did but it just simply isn’t working anymore.


Ok now I went back and double checked and he did do it this way but mine is alway’s returning…which means it never executes the code below.

When I removed this it worked fine…but why would it return null every tick if the component exists and is working?

It was a typo…lol

I was checking if it was NOT EQUAL TO and returning lol

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.