Warning C4996: Unreal Engine 4.18 'UPhysicsHandleComponent::GrabComponent' is deprecated (fixed)

	PhysicsHandle->GrabComponent(
		ComponentToGrab, //ComponentToGrab
		NAME_None, //grab what bone name, if any
		ComponentToGrab->GetOwner()->GetActorLocation(), //grab location
		true //allow rotation
	);

When you compile this code in Unreal 4.18, you’ll get this warning since this GrabComponent seems to be deprecated
warning C4996: 'UPhysicsHandleComponent::GrabComponent': Please use GrabComponentAtLocation or GrabComponentAtLocationWithRotation Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile

Instead of using GrabComponent, you can use GrabComponentAtLocation or GrabComponentAtLocationWithRotation instead

	PhysicsHandle->GrabComponentAtLocation(
		ComponentToGrab, //ComponentToGrab
		NAME_None, //grab what bone name, if any
		ComponentToGrab->GetOwner()->GetActorLocation() //grab location
	);

With this code, as you fly around holding the object, the object will dangle wildly from the point at which it’s being held, like it’s being tossed about in a hurricane. This is because the object is being held at a single point and the rotation is being handled by the physics engine.

	PhysicsHandle->GrabComponentAtLocationWithRotation(
		ComponentToGrab, //ComponentToGrab
		NAME_None, //grab what bone name, if any
		ComponentToGrab->GetOwner()->GetActorLocation(), //grab location
		ComponentToGrab->GetOwner()->GetActorRotation() //grab rotation
	);

With this updated code, as you fly around holding the object, the object will always point in the same direction (rotating in your hands, to maintain the the held object’s same rotation) as your point of view changes. This is because the rotation is no longer being calculated on the fly. Instead rotation is being passed as a parameter to the method.

13 Likes

Thank you.
And for anyone stuck on this (like I was), with newer versions of Unreal Engine you also need to include the header file of UPrimitiveComponent in order to be able to call GetOwner on it:

#include "Components/PrimitiveComponent.h"
8 Likes

Thank you both this solved my problem!

1 Like

Same here… I’ll stop banging my head against the desk now!

THANKS

1 Like

I figured out the GrabComponentAtLocation() but thank you for the GrabComponentAtLocationWithRotation().
Kind regards, Peter

1 Like

Thank you guys so much!

If you get the following error code:- “FMeshDrawSingleShaderBindings” is undefined - please use this PrimitiveComponent.h include instead

#include “Runtime/Engine/Classes/Components/PrimitiveComponent.h”

reported version UE 4.22

Edit: Include the following header file to the VertexFactory.h - #include “Runtime/Renderer/Public/MeshDrawShaderBindings.h”

4 Likes

This is super important as the error message unreal provides - Pointer to incomplete class type is not allowed - on the ComponentToGrab object is pretty useless. I found the answer by mix of stack overflow and seeing what object type HitResult.GetComponent() returned, but I’m glad someone posted the solution on the forums so others have help if they need it.

1 Like

Privacy & Terms