GrabComponent working but getting error with ComponentToGrab FIX:)

Hey guys so with all the new updates I found that you had to switch from Dans format to

if (ActorHit){
PhysicsHandle->GrabComponentAtLocationWithRotation(
ComponentToGrab,
NAME_None,
ComponentToGrab->GetOwner()->GetActorLocation(),
ComponentToGrab->GetOwner()->GetActorRotation()
);
}

BUT THEN I found that

ComponentToGrab-> Kept getting a red error under it saying -

“Pointer to incomplete class type is not allowed”

I would Build and be able to play just fine in both Unreal and VS But the red lines were really hurting my ocd
SO I found a quick fix that worked perfectly

All you need to do is write it out like this

if (ActorHit) {
if (!PhysicsHandle)
{
return;
}

	PhysicsHandle->GrabComponentAtLocationWithRotation(
		ComponentToGrab,
		NAME_None,
		ActorHit->GetActorLocation(),
		ActorHit->GetActorRotation()
	);
}

Changing ComponentToGrab->GetOwner()->GetActorLocation to simply ActorHit->GetActorLocation(),
Also NOTE that I left the first ComponentToGrab, in because it is still needed.

4 Likes

This was a bug I found and fixed just in case anyone needs it!

2 Likes

So you’re saying the code should be written like this?

if (ActorHit) {

if (!PhysicsHandle)
{

PhysicsHandle->GrabComponentAtLocationWithRotation(
ComponentToGrab,
NAME_None,
ActorHit->GetActorLocation(),
ActorHit->GetActorRotation()
);

return;

}

if (ActorHit)
{

if (!PhysicsHandle) { return; }

PhysicsHandle->GrabComponentAtLocationWithRotation(
ComponentToGrab,
NAME_None,
ActorHit->GetActorLocation(),
ActorHit->GetActorRotation()
);

}

The code should be written like this the only difference is you are only returning if you get a nullptr such as it says in !PhysicsHandle

Thanks, was a bit lost.

I really enjoyed this solution, really thx mate, you are the beast

I don’t think it was a bug. You have to add to the Grabber.cpp file the following header file:
#include “Components/PrimitiveComponent.h”

10 Likes

Privacy & Terms