Class definition breaks after adding #include

I have the following header file which compiles with no errors:

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


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

public:	
	UGrabber();

protected:
	virtual void BeginPlay() override;

public:	
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private:
	APlayerController* player;
	FVector PlayerViewLocation;
	FRotator PlayerViewRotation;
	float Reach = 100.f;
};

I am trying to add a UPhysicsHandleComponent variable which requires including "PhysicsEngine/PhysicsHandleComponent.h". When I add the include at the top, it breaks the UCLASS macro and says that the declaration has not storage class or type specifier.

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

I’m not sure how to format the include so it fits with the IWYU specification.

I’m not sure why that would break it, but I would say that you probably don’t need to include this in your header file. The usual way is to include it within your .cpp file, and in the .h you declare the variable with forward declaration

i.e. you put class in front of the variable like this:

class UPhysicsHandleComponent* MyComponent

or you declare the class at the top of your .h file:

//includes here

class UPhysicsHandleComponent;

UCLASS(....)
....

This basically tells the compiler that ‘I have a class called UPhysicsHandlerComponent’, so consider that an acceptable type for now and we’ll get the actual class definition later in the compilation process.

I found that running project → rescan solution will often clear up these issues between the compiler and Unreal. I’m still confused as to which #includes to place where. Usually I include any class that is used by a predeclared variable at the top of the header file, but before the generated.h. Any class used by variables declared only in the cpp, goes at the top of the cpp file, but after the #include .h

Are those steps correct?