Compiler is kidding me

Do you know the problems your IDE is sometimes throwing at you even if it compiled the same code earlier?
Currently im in this situation: I want to create an Actor which will Print out a Debug Message when Colliding the Trigger Box, which i attached to it. I want to print out the Name of the Actor inside a FString. But for some reason it is calling me that it has problems “class type of pointer-to-incomplete is not valid”

If you got some time pls check out my .cpp and my .h and explain to me why this is happening. I dont understand this atm since im new to this(UE)

.cpp

#include "ItemPickup.h"
#include <Components/MeshComponent.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>


// Sets default values
AItemPickup::AItemPickup()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	//Create Components

	this->SceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene Component"));
	this->RootComponent = SceneComponent;
	this->ItemMesh = CreateAbstractDefaultSubobject<UStaticMeshComponent>(TEXT("Item Mesh"));
	this->ItemMesh->AttachToComponent(SceneComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
	this->RotationRate = FRotator(180.0f, 0.0f, 0.0f);
	this->Speed = 1.0f;

	//Trigger Box
	this->BoxCollider = CreateDefaultSubobject<UBoxComponent>(TEXT("Collider Box"));
	this->BoxCollider->bGenerateOverlapEvents = true;
	this->BoxCollider->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
	this->BoxCollider->OnComponentBeginOverlap.AddDynamic(this, &AItemPickup::OnOverlapBegin);
	this->BoxCollider->AttachToComponent(SceneComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

}

// Called when the game starts or when spawned
void AItemPickup::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AItemPickup::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	this->AddActorLocalRotation(RotationRate * DeltaTime * Speed);

}

void AItemPickup::OnInteract()
{

}

void AItemPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (OtherActor != nullptr && OtherActor != this && OtherComp != nullptr)
	{

		FString PickUp = FString::Printf(TEXT("Picked Up : %s"), Name);

		GEngine->AddOnScreenDebugMessage(2, 5.0f, FColor::Blue, PickUp);

		OnInteract();
	}
}

.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/BoxComponent.h" 
#include "ItemPickup.generated.h"

UCLASS()
class SPACEGAME_API AItemPickup : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AItemPickup();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnyWhere, BlueprintReadOnly, Category = Item)
	int32 Value;

	UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Item: Used"))
	void Used();
	
	UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = "Item: Dropped"))
	void Dropped();

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = pickup)
	UStaticMeshComponent* ItemMesh;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = pickup)
	FRotator RotationRate;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = pickup)
	USceneComponent* SceneComponent;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = pickup)
	float Speed;

	// Pickup Mechanic
	UPROPERTY(EditAnyWhere)
	UBoxComponent* BoxCollider;

	UPROPERTY(EditAnyWhere)
	FString Name;

	UFUNCTION()
	virtual void OnInteract();
	
	UFUNCTION()
	void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};

Can you provide the specific error?

Hey there, telling where it fails would be helpful.

At first there seems to be something wront with
this->ItemMesh->AttachToComponent(SceneComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

this is the “class type pointer-to-incomplete is not valid” issue

The “String”-Problem is solved right now. But after i add this, my Log says: “class UObject has no Member BeginPlay”(It’s about Super::BeginPlay();

Hi,

The error is probably caused by this line:

FString PickUp = FString::Printf(TEXT("Picked Up : %s"), Name);

Your Name property here is a FString which causes issues here because TEXT macro doesn’t accept FStrings. You need to pass a TCHAR. You can simply convert your Name variable to TCHAR type by putting a dereference operator * behind it as follows:

FString PickUp = FString::Printf(TEXT("Picked Up : %s"), *Name);

Hope this helps.

Most likely, go to YourProjectName.h in visual studio or xcode, and change:

#include "CoreMinimal.h"

to:

#include "Engine.h"

Hope It Helps,

P.S. Engine.h will take longer to compile by about 25% more time, however it does unlock a lok more tools and functionalities in Unreal Engine.

Still would like for you to show us the error you are seeing rather than interpreting it to us. If you understood enough to decide what we should see then you wouldn’t need our help. So don’t hold back with info.

atleast it compiles now.
Now i just need to find a way to assign the Name to this class