Crashing on Startup PhysicsHandle->GetGrabbedComponent()

Hello, so I’ve noticed a couple of little issues in my file but this is the first time that it’s seemed to crash every time I attempt to play.

Let’s look at my code first. This is in version 4.19

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

// LINE TRACE and see if we hit any actors with physics body
// Get Player viewpoint this tick
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
	OUT PlayerViewPointLocation,
	OUT PlayerViewPointRotation
);
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
// if the physics handle is attached
if (PhysicsHandle->GetGrabbedComponent())
	// move the object we're holding
{
	PhysicsHandle->SetTargetLocation(LineTraceEnd);
}

}

void UGrabber::Grab()
{
UE_LOG(LogTemp, Warning, TEXT(“Grab Pressed”))

//TODO ray-cast and grab
auto HitResult = GetFirstPhysicsBodyInReach();
auto ComponentToGrab = HitResult.GetComponent();
auto ActorHit = HitResult.GetActor();
// try to reach any actors with physics body collision channel set

///if we hit something then attach a physics handle
if (ActorHit)
{
	// attach a physics handle
	PhysicsHandle->GrabComponentAtLocationWithRotation(
		ComponentToGrab,
		NAME_None,
		ComponentToGrab->GetOwner()->GetActorLocation(),
		ComponentToGrab->GetOwner()->GetActorRotation()
	);
}

}

So I poked around a bit and did a little debugging. A couple things I’ve found:

  1. commenting out the PhysicsHandle stuff in the tick component allows the game to run without error, but the chair won’t move, obviously.

  2. I tried printing out what component it was attempting to grab and occasionally it would return (null). That didn’t bother me. But occasionally it would return Korean characters. Something like “꽸홭翽”

I tried deleting and then replacing the chair and found that now wherever I was in the room, it would return the Korean chracters, not just when I was at the chair.

Thanks for taking a look. Let me know if you have the same problem or if you know of a fix.

hows it going bud

I don’t have the same problem, as I mange to make it pass this step without having to much of an issue besides a small redline error that i couldnt get to go away.

I am curious though if you found a solution, just for the sake of having a solution so if anyone else stumble’s upon it :smiley:

I’m still kind of hitting my head against the wall on this one. I wonder if I’m missing an include. I’ve got

#include “Grabber.h”
#include “DrawDebugHelpers.h”
#include “Engine/World.h”
#include “UObjectBaseUtility.h”
#include “Gameframework/Actor.h”

Are you sure PhysicsHandle is a non-null pointer at that point? I.e. did you remember to assign GetOwner->FindComponentByClass<UPhysicsHandle>() to it in BeginPlay(), and is that the only assignment?

Check out the log. It should give you the filename and line number of the crash, if it’s caused by your code. That’ll help you narrow it down.

If not, it might be worth using a paste service to show the full code.

Hey Nick!

I’m having the exact same problem as you (I think). I’m 11 minutes into Lecture 91 and every time I hit Play, Unreal crashes.

I tried moving FindPhysicsHandle() (and only FindPhysicsHandle) into TickComponent() and now the crashing has stopped.

IE:

// Look for attached physics handle
void UGrabber::FindPhysicsHandle()
{
	PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
	if (PhysicsHandle)
	{
		/// If Physics Handle is found
		/// Establish Player Viewpoint
		GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerViewpointCamera, PlayerViewpointRotation);

		FVector LineTraceEnd = PlayerViewpointCamera + (PlayerViewpointRotation.Vector() * Reach);

		if (PhysicsHandle->GrabbedComponent)
		{
			PhysicsHandle->SetTargetLocation(LineTraceEnd);
		}
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("Unable to find %s"), *(GetOwner()->GetName()))
	}
}


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

        // Find out if the Physics Handler exists
	FindPhysicsHandle();
}

I hope that helps you as much as it helped me! (I’ve been pulling my hair out for an hour.)

I know this is an older post. But, for some reason, my DefaultPawn_BP had lost its PhysicsHandle component. I added the component again and everything ran fine.

I had to check the logs to see that the error message we had made earlier in the section for the PhysicsHandle was triggered.

That’s just what I needed, thanks Choco. A lot of time spent looking for rouge null pointers. I had re-created my BPs earlier trying to isolate a problem and it was as simple as that…
Cheers.

Privacy & Terms