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);
};