Grab Component Crash

Im just trying to translate the content example blueprint to grab objects. But the crash always happens on this line

PhysicsHandle->GrabComponent(PhysicsObject, GC_OutHit.BoneName, GC_OutHit.Location, true);

Where PhysicsObjecy = GC_OutHit.GetComponent(); and where GC_OutHit, is the Output hit result from a Line trace to the static mesh. ¿What am I doing wrong?

Why the $#$% does nobody answers my questions?!!

No one yet?!

Hey

Could you provide more information on what you were doing when the crash occurred? Are you following a tutorial and if so which one? Does the crash happen when you compile the code or Play in Editor or when doing something else? Additionally, could you post the log files inside the Saved->Logs folder from the crash?

Cheers

No, Im not following a tutorial. Im just following the content example BluePrint to grab objects, and put it into C++. For now, I’ve been able to create correctly 1 trace, the first one to check what object the trace is hitting and the second one to grab the object is the problem. Is just that It seems I can’t access the UPhysicsHandleComponent class, even when Im trying to change any value of a variable, it crashes the editor.

The crash happens when Im playing, I can compile the editor without issues.

Im declaring my object as this, UPhysicsHandleComponent* PhysicsHandle;

I checked my log file, and well is not in english cause Im using a different language version of the engine, the log file don’t say something about the crash. Then, when the editor crashes and visual studio interrupts the process, it don’t tell me the reason why it’s crashing, it doens’t matter what function or variable Im accessing through the UPhysicsHC class, it always crash the editor.

Hey

Which blueprint were you basing your work on? When you open content example do you have to switch the level and if so which do you switch to? Additionally, could you post the code you’re using to try to grab the object, both the Header and source files.

Its the default BP_Character that comes in the content example.

This is my .h

FCollisionQueryParams TraceParams;
	UPhysicsHandleComponent* PhysicsHandle;
	UPrimitiveComponent* PhysicsObject;

Just declaring object classes.

this is the .cpp

void ACharacter::GrabObject()
{	
	FHitResult GC_OutHit(ForceInit);
	APlayerCameraManager* GPCM = UGameplayStatics::GetPlayerCameraManager(this, 0);
	TraceParams.bTraceComplex = true;
	TraceParams.AddIgnoredComponent(GetCapsuleComponent());
	if (GetWorld()->LineTraceSingle(GC_OutHit,
		GPCM->GetCameraLocation(),
		GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())),
		ECollisionChannel::ECC_PhysicsBody,
		TraceParams))
	{
		PH_Active = true;
		DrawDebugLine(GetWorld(),
			GPCM->GetCameraLocation(),
			GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())),
			FColor::Green,
			true,
			10.f,
			0,
			2.f);
		PhysicsObject = GC_OutHit.GetComponent();
		PhysicsObject->InitializeComponent();
		PhysicsHandle->LinearDamping = 200.f;
		PhysicsHandle->LinearStiffness = 750.f;
		PhysicsHandle->AngularDamping = 500.f;
		PhysicsHandle->AngularStiffness = 1500.f;
		PhysicsHandle->InterpolationSpeed = 50.f;

		PhysicsHandle->GrabComponent(PhysicsObject, GC_OutHit.BoneName, GC_OutHit.Location, true);
		PhysicsHandle->SetTargetLocation(GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())));

	}
	else
		PH_Active = false;

}

I’ve been thinkking that Im no initializing something for the handler. The crash keeps happening on the same line, but when I delete it then it crashes on the loines where Im modifying the variables. I included the “PhysicsHandlerComponent.h” on my header, but I just don’t get what is going on.

Hello?! Is somebody here?

Hey

I apologize for the delay. I am still investigating this crash and will post an update here once I have more information.

Hey

In trying to test the issue I created a character class and added the code you provided to it. After resolving compiling errors I tried to play with the character and didn’t crash. Could you explain the steps you used so that I can try to reproduce this crash? Alternatively, you could upload a project where you’re experiencing this crash to dropbox and send me a pm on the forums with the link?

Humm… Is very weird that it didn’t crash with you. Well, Im running the editor with the “Development Editor” template. I Think is something with my project, Im gonna create a new project to see If I can send it to you.

BTW, you said it didn’t crash, but were you able to lift or grab the object?

, I made a new project and stills crashing the editor. Here’s the code I added in .H, because I won’t paste th default code that comes from the tempalte.

	bool PH_Active;
	FCollisionQueryParams TraceParams;
	class UPhysicsHandleComponent* PhysicsHandle;
	class UPrimitiveComponent* PhysicsObject;

	void GrabComp();
	void ReleaseComp();

Now the .CPP

These are the BindingAction functions

InputComponent->BindAction("Grab", IE_Pressed, this, &APHTestCharacter::GrabComp);
	InputComponent->BindAction("Grab", IE_Released, this, &APHTestCharacter::ReleaseComp);

For Now, I just only made the GrabComp Function

void APHTestCharacter::GrabComp()
{
	 FHitResult GC_OutHit(ForceInit);
     APlayerCameraManager* GPCM = UGameplayStatics::GetPlayerCameraManager(this, 0);
     TraceParams.bTraceComplex = true;
     TraceParams.AddIgnoredComponent(GetCapsuleComponent());
     if (GetWorld()->LineTraceSingle(GC_OutHit,
         GPCM->GetCameraLocation(),
         GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())),
         ECollisionChannel::ECC_Visibility,
         TraceParams))
     {
         PH_Active = true;
         DrawDebugLine(GetWorld(),
             GPCM->GetCameraLocation(),
             GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())),
             FColor::Green,
             true,
             10.f,
             0,
             2.f);
         PhysicsObject = GC_OutHit.GetComponent();
         PhysicsObject->InitializeComponent();
         PhysicsHandle->LinearDamping = 200.f;
         PhysicsHandle->LinearStiffness = 750.f;
         PhysicsHandle->AngularDamping = 500.f;
         PhysicsHandle->AngularStiffness = 1500.f;
         PhysicsHandle->InterpolationSpeed = 50.f;
         PhysicsHandle->GrabComponent(PhysicsObject, GC_OutHit.BoneName, GC_OutHit.Location, true);
         PhysicsHandle->SetTargetLocation(GPCM->GetCameraLocation() + (FVector(500.f) * FVector(GPCM->GetCameraRotation().Vector())));
 
     }
     else
         PH_Active = false;
}

Hey

Copying the code you posted gave me a compile error at the line DrawDebugLine() as well as the PhysicsHandle calls. I was able to resolve teh DrawDeugLine error by including DrawDebugHelpers.h - is there another file that needs to be included to allow PhysicsHandle to work properly?

To fix the drawdebug line, include the “Engine.h” but it seems you fixed it with another way.

Yes, to make the PhysicsHandle work properly you have to also include the:

#include "PhysicsEngine/PhysicsHandleComponent.h"

I’m still getting compile errors when trying to add the code to a character class. Would it be possible for you to put your project on dropbox and then send me a private message on the forums with a link to the project?

! I was f$#$% able to FIX IT! Too bad the Documentation don’t has enough info about it, or may be I was ignorant. The physics Handle component has to first be initialized like a character component, like a camera or a Mesh to make it work.

So in the H i added:

UPROPERTY(VisibleDefaultsOnly, Category = PhysicHandle)
	class UPhysicsHandleComponent* PH;

So this means it will be visible on the BP, only defaults.

Now this goes in the cpp, where we code the first constructor to initialize the character

	PH = CreateDefaultSubobject<UPhysicsHandleComponent>(TEXT("PhysicsHandle"));
	PH->LinearDamping = 200.f;
	PH->LinearStiffness = 750.f;
	PH->AngularDamping = 500.f;
	PH->AngularStiffness = 1500.f;
	PH->InterpolationSpeed = 50.f;

Now, you can use the PH pointer variable on any function you want without crashing anything