Unable to add Physics Handle in script

Hey guys as the name suggests I am unable to add the “UPhysicsHandleComponent” into the Grabber.h. When I do it says no reference found, when I add include “PhysicsEngine/PhysicsHandleComponent.h” to try and fix that I get a whole bunch of errors in the Grabber.cpp saying "name followd by ‘::’ must be a class or namespace name. It’s like it no longer recognizes the Grabber.h file

here is the grabber.h code

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “Grabber.generated.h”
#include “PhysicsEngine/PhysicsHandleComponent.h”

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UGrabber : public UActorComponent
{
GENERATED_BODY()

public:
// Sets default values for this component’s properties
UGrabber();

// Called when the game starts
virtual void BeginPlay() override;	

// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:
// How far ahead of the player can we reach in CM
float Reach = 100.f;

UPhysicsHandleComponent* PhysicsHandle = nullptr;

};

Apologies for the poor formatting in the above.

I think I may have fixed the problem. It seems that you have to have the #include “Grabber.generated.h” as the last one in the #include 's list otherwise it doesn’t work.

Can anybody confirm that?

so my includes now looks like this

#include “CoreMinimal.h”
#include “Components/ActorComponent.h”
#include “PhysicsEngine/PhysicsHandleComponent.h”
#include “Grabber.generated.h”

1 Like

I was having the same problem what i did was add in the Grabber.h code i put the #includes as you have above and in the Grabber.cpp code i put
#include “Grabber.h”
#include “DrawDebugHelpers.h”
#include “CollisionQueryParams.h”
#include “PhysicsEngine/PhysicsHandleComponent.h”

hopefully this helps if you havn’t fixed it already.

I was having the same annoying problem for a very long time so thank you for sharing this!

This is indeed correct. Whenever you include stuff you have to make sure the classname.generated.h is dead last in the list otherwise you will run into errors.

I am at UE4 4.21.1 and bumped into a similar problem which was caused by a different line.

my Grabber.h included

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PhysicsEngine/PhysicsHandleComponent.h"
#include "Grabber.generated.h"

which broke GENERATED_BODY() macro with the following error:

Error (active) E0077 this declaration has no storage class or type specifier BuildingEscape

this might as well be in mandarin as far as my knowledge of UE4 goes :stuck_out_tongue:

The fix was to remove #include "CoreMinimal.h".
Everything compiles and works as expected after removing this include, however I have no I idea what this header file brings and why it was safe to remove it.

Thanks

EDIT:
Apparently, what I have just found out is that this is ONLY an IntellySense issue.
Installed a trial version of VisualAssist X just now and it all shows up correctly.

Using Unreal 4.21.1 and VS Community 2017 14.16.27023, I had same issues as @dmitrymatveev. GENERATED_BODY() produced the same error message. SUPER:BeginPlay(); and Super::TickComponent(DeltaTime, TickTyoe, ThisTickFunction): produced errors showing they had not been defined. The UE_LOG line for the physics handle produced an error that an expression was required though the line was completed identically to the lecture solution. Could not compile the solution.

I closed VS and reopened. All errors vanished. Project compiled. It looks like VS was having some sort of issue realted to inclusion of PhysicsHandleComponent.h.

Privacy & Terms