This is the code i use for this error. Its a header file named KeyPickup “KeyPickup.h”
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "KeyPickup.generated.h"
#include "Components/BoxComponent.h"
UCLASS()
class MYPROJECT_API AKeyPickup : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AKeyPickup();
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)
UStaticMeshComponent* PickupMesh;
UPROPERTY(EditAnywhere)
USceneComponent* PickupRoot;
UPROPERTY(EditAnywhere)
UBoxComponent* PickupBox;
UFUNCTION()
void onPlayerOverlapPickupBox(UPrimitiveComponent*overlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};
PS : if you need more clarification about which files i need to show here… please do inform me… thanks
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "KeyPickup.generated.h"
UCLASS()
class POGOPAINTER_API AKeyPickup : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AKeyPickup();
UPROPERTY(EditAnywhere)
class UStaticMeshComponent* PickupMesh;
UPROPERTY(EditAnywhere)
class USceneComponent* PickupRoot;
UPROPERTY(EditAnywhere)
class UBoxComponent* PickupBox;
UFUNCTION()
void onPlayerOverlapPickupBox(UPrimitiveComponent* overlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
.cpp:
// Fill out your copyright notice in the Description page of Project Settings.
#include "KeyPickup.h"
#include "Components/StaticMeshComponent.h"
#include "Components/BoxComponent.h"
// Sets default values
AKeyPickup::AKeyPickup()
{
// 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;
}
// Called when the game starts or when spawned
void AKeyPickup::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AKeyPickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AKeyPickup::onPlayerOverlapPickupBox(UPrimitiveComponent* overlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
}
i followed your code… looks like there’s a little less errors on this but still the main focus of the error does not subsides…
based on the declaration error, should I remove the BeginPlay() and Tick() function declaration in header file?
The error that came out in the registry is as if the changes I mentioned were not applied. Place everything as in the code I left at the top and compile. If you continue the problem try to create a new project and do the same procedure.
Solved this by creating a new project entirely… encounter another problem when tried adding my new code in it…
(since this is new project, i use different name file)
Pick.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Pick.h"
#include "Components/StaticMeshComponent.h"
#include "Components/BoxComponent.h"
// Sets default values
APick::APick()
{
// 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;
PickupRoot = CreateDefaultSubobject<USceneComponent>(TEXT("PickupRoot"));
RootComponent = PickupRoot;
PickupMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PickupMesh"));
PickupMesh->AttachToComponent(PickupRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
PickupBox = CreateDefaultSubobject<UBoxComponent>(TEXT("PickupBox"));
//PickupBox->SetWorldScale3D(FVector(1.0f, 1.0f, 1.0f));
PickupBox->bGenerateOverlapEvents = true;
PickupBox->OnComponentBeginOverlap.AddDynamic(this, &APick::onPlayerOverlapPickupBox);
PickupBox->AttachToComponent(PickupRoot, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
}
// Called when the game starts or when spawned
void APick::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APick::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void APick::onPlayerOverlapPickupBox(UPrimitiveComponent* overlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
Destroy();
}
In your pick.h header file my understanding is #include “pick.generated.h” call must be the last on the list
You cannot access bGenerateOverlapEvents directly, it is private. You have to use the setter:
PickupBox->SetGenerateOverlapEvents(true);
See: UPrimitiveComponent | Unreal Engine Documentation
(part of the problem may be that this api reference doesn’t show bGenerateEvents but if you look at the source code it is clear it is private):
There is a lot of online conversation over the years on this error but I have not seen anything that convincingly specifies the cause.
Things people have tried that might work for you are:
Clean rebuild:
launch your project from Visual Studio with the UE editor closed
select under the build menu, select Rebuild All
run the project from visual studio (which will start the editor for as long as you are running the project)
Try compiling from the editor
For some people, this seems to have solved their problem
Check your reflection parameters UProperty() etc. For some, the problem was caused by having incorrect parameters ( they would be in your header file, you may not have any based on what I have seen)
Double-click on the .sln file or start visual studio and “open solution”. You will then select the TestDrag.sln file in D:\Unreal Projects\TestDrag folder