"GENERATED_BODY()" error

I am working on creating a simple coin-pickup game using UE5 and C++.
I watched a YouTube video, and I wrote codes following the video. In the video, there is no error message, but there is in mine.
I am new to UE5 and C++. Also, I am new to post a question in this community so I am not sure if it is ok to post whole code here or not, but I will.
Why GENERATED_BODY() got error in my codes? Actually, the codes in the video, this line does not have error message.
Using Visual Studio.

the error message that the line got: this declaration has no storage class or type specifier.

Header file

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CPT_CoinPickupActor.generated.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"


class UStaticMeshComponent;
class URotatingMovementComponent;
class USphereComponent;
class UNiagaraSystem;
class USoundBase;

UCLASS()
class COINPICKUPTUTORIAL_API ACPT_CoinPickupActor : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	ACPT_CoinPickupActor();

	UFUNCTION()
	void OnBeginOverlapComponentEvent(
		UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
		int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
	);

protected:
	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	TObjectPtr<UStaticMeshComponent> MeshComponent;

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	TObjectPtr<URotatingMovementComponent> RotatingMovementComponent;

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	TObjectPtr<USphereComponent> ColliderComponent;

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	TObjectPtr<UNiagaraSystem> OnPickupEffect;

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	TObjectPtr<USoundBase> PickSound;

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	float VolumeMultiplier{ 0.5 };

	UPROPERTY(EditDefaultsOnly, Category = "Coin Pickup Tutorial")
	float PickEffectSpawnOffset{ 90 };
};

CPP

#include "CPT_CoinPickupActor.h"

#include "Components/SphereComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/RotatingMovementComponent.h"
#include "Kismet/GameplayStatics.h"

#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"

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

	ColliderComponent = CreateDefaultSubobject<USphereComponent>("ColliderComponent");
	SetRootComponent(ColliderComponent);
	ColliderComponent->SetGenerateOverlapEvents(true);
	ColliderComponent->SetCollisionEnabled(ECollisionEnabled::QueryOnly);
	ColliderComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
	ColliderComponent->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);

	ColliderComponent->OnComponentBeginOverlap.AddDynamic(
		this, &ACPT_CoinPickupActor::OnBeginOverlapComponentEvent
	);

	MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>("MeshComponent");
	MeshComponent->SetupAttachment(ColliderComponent);
	MeshComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision);
	MeshComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
	MeshComponent->SetGenerateOverlapEvents(false);

	RotatingMovementComponent = CreateDefaultSubobject<URotatingMovementComponent>("RotatingMovementComponent");
}

void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(
	UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
)
{
	if (!Cast<ACharacter>(OtherActor)) return;

	if (PickSound)
	{
		UGameplayStatics::PlaySoundAtLocation(
			this, PickSound, GetActorLocation(), VolumeMultiplier);
	}

	if (OnPickupEffect)
	{
		const FVector Offset = GetActorUpVector() * PickEffectSpawnOffset;
		UNiagaraFunctionLibrary::SpawnSystemAtLocation(
			this, OnPickupEffect, OtherActor->GetActorLocation() + Offset);
	}

	Destroy();
}

Build file

using UnrealBuildTool;

public class CoinPickupTutorial : ModuleRules
{
    public CoinPickupTutorial(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "EnhancedInput" });
        PrivateDependencyModuleNames.AddRange(new string[] { "Niagara" });
    }
}

You also need to post the errors that you’re getting. No one is going to put that code into a project to try and replicate your problem.

1 Like

try to put it the last one of the headers

like this:

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"

#include "CPT_CoinPickupActor.generated.h"

Thanks for the advice. I just edited my post.

I put the line there, but it did not solve the problem I got there. I’m sorry, but I really appreciate your help.

Your code seem good.

What engine version are you using?
Older versions used this:
GENERATED_UCLASS_BODY()
But new version use this.
GENERATED_BODY()

Your build.cs has this in the header?

using System;
using System.IO;
using UnrealBuildTool;

Your files are called like this?

"CPT_CoinPickupActor.h"
"CPT_CoinPickupActor.cpp"

Ok… forget about version… you must use this then…
GENERATED_BODY()

I’m using 5.2.1.
I put what you suggested, but it does not help, unfortunately.
I also got an error saying “There were build errors. Would you like to continue and run the last successful build?”

Show the compiler errors

look the last two lines…

You have generated files in the wrong place.

like i said you in my first post…

fix it in all your files

Hello,
Thank you for the advice, and I solved the error that you mentioned.
HOwever, I still have some errors.

i think you have some visual studio problem too

use this command to compile and check it

call "C:\Program Files\Epic Games\UE_5.2\Engine\Build\BatchFiles\Build.bat"  CatharsisEditor Win64 Development 

"C:\....\YorProjectName.uproject" -waitmutex -NoHotReload

(You must to use de console CMD)