Coin pickup counter with UE5 and C++

Hi, I have been working on creating a super simple coin-pickup game.
I have wrote some codes for pick up coins. Now, I am tying to find any source that I can use for coin counter.
If anyone know good source, could you let me know, please?
I have already wrote some codes for pickup. I paseted them below.
It would be grate if you could give me some codes that for counter.

code for 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();
}

Header

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "CPT_CoinPickupActor.generated.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 };
};

build file

using System;
using System.IO;
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" });
    }
}

Hello @yuma9921jp ,

If you want to create a coin pickups, you can try watch these videos.
Experiment 5 - Pickupable - YouTube
The video is not in english, but the C++ code written in english. Maybe you can just see the code there. That video final product is just a simple coin pickup and will be counted in character and show it to screen.

Thank you for the suggestion. But, it seems like it it with UE4. Are there any differences?

yes it is with UE4. Actually there is almost no difference in the code itself between those version. Nearly everything is the same except for the UI and there are some new features that implemented inside UE5.

Code / Logic that work in UE4, will also work in UE5 without any difference in the code

Hi, I have been watching the YouTube video.
I got confused since I already have my codes, and the codes in the video are completely different from mine.
Could you help me, please??

For now, I am watching the video explaining how to add a coin counter. I tried to imitate what he did in the video by following the video.


Here, in the video, he goes to the content category and chooses coin. (If you can watch the video, it starts from around 4:25-) In my UE5, there is no button saying coin. Then what I choose there?

Hello @yuma9921jp ,

sure I will help you. The button coin is not actually a button, it is just a variable in C++ that named Coin. That video use the Coin variable for counting the coin (When player overlap with the coinpickup in world, The Coin variable value will incremented by one).

Do you have a variable for storing how much coin your character already picked up? If you have already, you should bind that variable to the widget (In the video, bind the coin variable). But if you haven’t created that yet, consider watching the previous video.

If you have further question, feel free to continue this!

I have watched the videos and he explained how to add strings for storing how many coins the character picked up. However, as I said before, since I have already written some codes and created a coin pickup game without a counter, and his codes are completely different, I got confused. It seems like he created new pickup_coin.cpp and .h from his UE screen. (part 4 really beginning).


Of course I do not have a file named “pickupable” but I do have something similar.
Then, tried to create new files, but mine does not show up “create C++ class derived from Pickupable”
MIne show me “create child blueprint class”

How can I create a file for counting the coin numbers class? I am using Visual Studio.
Or I just add some codes to codes that I have already written??

I’m sorry if I make you confused too, but I am new to c++ and UE5.

Hello,

you don’t need to do exactly the same to the video so just use your own code. You can assume that Pickup_Coin.cpp in the video, is the same with your BP_CoinPickupActor since that actor is the one that can be picked up right?

How can I create a file for counting the coin numbers class?

You don’t need to create a specific class to do the counting. You can just do that in your character class for example. Just create a variable in your character to store how much coin already picked up and bind it to the widget.

When your BP_CoinPickUpActor is overlapped with chara / picked up, just increment that variable you created in character for storing the coin.

If your character created in full C++ and your coin is in full BP, to increment the variable in character, you should create a function with UFUNCTION macro or just put the BlueprintReadWrite in variable UPROPERTY. Example:

You can choose one of these
1. Create a function in character

UFUNCTION(BlueprintCallable)
void IncrementCoin();

2. Use BlueprintReadWrite in counter variable

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Counter")
uint16 CoinAmount;

If you use option one, later in blueprint you can call that function from the character reference, BUT if option two, you can get and modify the CoinAmount variable from the blueprint.

Hello,
Thank you for the advice. After that, I have rewatched the videos again, and I put some exactly same codes what he does in the video(I know you told me I do not have to follow exactly the same but).
Then I followed your advice and I put this in my codes too.UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = “Counter”)
uint16 CoinAmount;

However, I’m still confused about what I should put inside and what codes I have to write in my cpp, header, and the build file.

I put my cuurent code here, and could you check them and give me some advice or some codes for me, please???
Again, I am so sorry for asking some stupid questions again and again, but I am new to C++ and UE. I would be happy if you understood me.

my codes

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


	//coin counter
	//Coin = 0;
}

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


//void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
//{
//	Coin += Value;
//}

/*
void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(
	UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
)
{	

	Super::OnSphereBegiOveralap(OverlappedComponent, OtherActor,OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
	AE_PickupableCharacter* Char = Cast<AE_PickupableCharacter>(OtherActor);
	if(Char)
	{
		Char-> AddCoinByValue(CoinValue);
		Destroy();




	}
	

}






CPT_CoinPickupActor::Apickup_Coin()
{
	CoinValue = 1;

}
*/

header



#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "CPT_CoinPickupActor.generated.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
	);

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Counter")
	uint16 CoinAmount;

	///???


	//add player coin amount by some value
	//void AddCoinByValue(uint8 Value);



	/*
	UFUNCTION()
	virtual void void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, Uprimi...)
	In my case, what should it look like??
	*/

protected:
	//Constructor







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


	//coint that already picked up by player
	//UPROPERTY(VisibleAnywhere, Category = "Coin Pickup Tutorial")
	//uint32 Coin;
	//The codes I added for the counter

	//the conin value
	//UPROPERTY(EditAnywhere, Category = "Coin")
	//uint8 CoinValue;


	//Apickup_Coin();


	/*
	void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, Uprimi...)
	In my case, what should it look like???*/
};

build file


using System;
using System.IO;
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" });
    }
}

Some codes are commented out. commented out codes are the codes that I typed exactly the same (not all of them. I chenged some by following my original codes) from the videos.

Thank you

Hello, you don’t need to always say sorry about that xD I also understand that feeling also when I’m new so its perfectly fine.

UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = “Counter”)
uint16 CoinAmount;

You don’t want to put this variables on your PickupActor. You want that in your character class. You also want to remove all of your commented code, since it’s not in the correct class and some of it already implemented by you.

/*
void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, Uprimi…)
In my case, what should it look like???*/

In your case, this also need to be removed since you already have void OnBeginOverlapComponentEvent(…) and that is the same.

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

These piece of code, can be problematic if you put it in the constructor. Move it to BeginPlay() function.

AddCoinByValue(uint8 Value)

This function, also should be in your character class, not in your PickupActor class. You don’t want the PickupActor to save the coin amount. If you already have your custom character class, you should move this AddCoinByValue function and CoinAmount variable. CoinAmount will be incremented inside AddCoinByValue().

After then in your PickupActor BeginOverlap,

void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(...
)
{
	if (!Cast<ACharacter>(OtherActor)) return;

Instead of Casting it to normal character, put your custom character there, and call AddCoinByValue() there to increment it.

AYourCustomCharacter* Char = Cast<AYourCustomCharacter>(OtherActor);
if(!Char)
{return;}

Char->AddCoinByValue(1) 
// This 1 parameter is optional, if you want to make it without parameter it also fine

Thanks for the understanding.
I just modified my codes, and I got some errors. I put my codes below.
Also, I am not sure the last part of what you told me. (from After then in your PickupActor BeginOverlap,) What should I do.

As I said above, I put my codes here. PLease check them and tell me what I should do next. The codes I just added are with some comments above the code like ‘I just added Oct 4.’ Actually, I have not deleted some codes. If possible, could you tell me which codes I should delete. I am kind of afraid delete all of the commented off code.

Character header

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "InputActionValue.h"
#include "CoinPickupTutorialCharacter.generated.h"


UCLASS(config=Game)
class ACoinPickupTutorialCharacter : public ACharacter
{
	GENERATED_BODY()

	/** Camera boom positioning the camera behind the character */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class USpringArmComponent* CameraBoom;

	/** Follow camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* FollowCamera;
	
	/** MappingContext */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputMappingContext* DefaultMappingContext;

	/** Jump Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* JumpAction;

	/** Move Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* MoveAction;

	/** Look Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* LookAction;

	//code I just added(Oct4th)
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = “Counter”)
	uint16 CoinAmount;

public:
	ACoinPickupTutorialCharacter();
	

protected:

	/** Called for movement input */
	void Move(const FInputActionValue& Value);

	/** Called for looking input */
	void Look(const FInputActionValue& Value);
			

protected:
	// APawn interface
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
	
	// To add mapping context
	virtual void BeginPlay();

public:
	/** Returns CameraBoom subobject **/
	FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
	/** Returns FollowCamera subobject **/
	FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
};

character cpp



#include "CoinPickupTutorialCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"


//////////////////////////////////////////////////////////////////////////
// ACoinPickupTutorialCharacter

ACoinPickupTutorialCharacter::ACoinPickupTutorialCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
		
	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate

	// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
	// instead of recompiling to adjust them
	GetCharacterMovement()->JumpZVelocity = 700.f;
	GetCharacterMovement()->AirControl = 0.35f;
	GetCharacterMovement()->MaxWalkSpeed = 500.f;
	GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
	GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
}

void ACoinPickupTutorialCharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	//i just added code(Oct 4) got error
	ColliderComponent->OnComponentBeginOverlap.AddDynamic(
		this, &ACPT_CoinPickupActor::OnBeginOverlapComponentEvent
	);

	//Add Input Mapping Context
	if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
	{
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
		{
			Subsystem->AddMappingContext(DefaultMappingContext, 0);
		}
	}
}

//////////////////////////////////////////////////////////////////////////
// Input

void ACoinPickupTutorialCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	// Set up action bindings
	if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
		
		//Jumping
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);

		//Moving
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Move);

		//Looking
		EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Look);

	}

}

void ACoinPickupTutorialCharacter::Move(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D MovementVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	
		// get right vector 
		const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

		// add movement 
		AddMovementInput(ForwardDirection, MovementVector.Y);
		AddMovementInput(RightDirection, MovementVector.X);
	}
}

void ACoinPickupTutorialCharacter::Look(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D LookAxisVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// add yaw and pitch input to controller
		AddControllerYawInput(LookAxisVector.X);
		AddControllerPitchInput(LookAxisVector.Y);
	}
}

//i just added code(Oct 4) got error
void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

coinpickupactor header

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "CPT_CoinPickupActor.generated.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
	);

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Counter")
	uint16 CoinAmount;

	///???


	//add player coin amount by some value
	//void AddCoinByValue(uint8 Value);

	/*
	UFUNCTION()
	virtual void void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, Uprimi...)
	In my case, what should it look like??
	*/

protected:
	//Constructor

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


	//coint that already picked up by player
	//UPROPERTY(VisibleAnywhere, Category = "Coin Pickup Tutorial")
	//uint32 Coin;
	//The codes I added for the counter

	//the conin value
	//UPROPERTY(EditAnywhere, Category = "Coin")
	//uint8 CoinValue;


	//Apickup_Coin();


	/*
	void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, Uprimi...)
	In my case, what should it look like???*/
};

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

	

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

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


	//coin counter
	//Coin = 0;
}

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


//void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
//{
//	Coin += Value;
//}

/*
void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(
	UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
)
{	

	Super::OnSphereBegiOveralap(OverlappedComponent, OtherActor,OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
	AE_PickupableCharacter* Char = Cast<AE_PickupableCharacter>(OtherActor);
	if(Char)
	{
		Char-> AddCoinByValue(CoinValue);
		Destroy();




	}
	

}






CPT_CoinPickupActor::Apickup_Coin()
{
	CoinValue = 1;

}
*/

build file


using System;
using System.IO;
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" });
    }
}

Hello, I can see that your code is nearer to completing this feature.

//i just added code(Oct 4) got error
void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

That piece of code above, is in the correct class already. However, you haven’t declare it in your ACoinPickupTutorialCharacter.h file. so it should be like this.

Header File:
void AddCoinByValue(uint8 Value);

.cpp file:
void ACoinPickupTutorialCharacter::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

Second error,

//i just added code(Oct 4) got error
ColliderComponent->OnComponentBeginOverlap.AddDynamic(
	this, &ACPT_CoinPickupActor::OnBeginOverlapComponentEvent
);

That piece of code is in the wrong class. Lastly, I said that move this into beginplay function, what I mean is in the beginplay of your CoinPickupActor class not the beginplay in your character. You need to create a new begin play in your CoinPickupActor and put that code there.

header ACPT_CoinPickupActor:
virtual void BeginPlay() override;

cpp file:
void ACPT_CoinPickupActor::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

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

in your ACPT_CoinPickupActor.h, EVERY code that you comment, should be deleted since it’s just whether useless, redundant, or in the wrong place.

in your CoinPickupActor.cpp file, these commented code also need to be deleted:


//void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
//{
//	Coin += Value;
//}

/*
void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(
	UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
)
{	

	Super::OnSphereBegiOveralap(OverlappedComponent, OtherActor,OtherComp, OtherBodyIndex, bFromSweep, SweepResult)
	AE_PickupableCharacter* Char = Cast<AE_PickupableCharacter>(OtherActor);
	if(Char)
	{
		Char-> AddCoinByValue(CoinValue);
		Destroy();
	}
}

CPT_CoinPickupActor::Apickup_Coin()
{
	CoinValue = 1;
}
*/

Ok, your confused part of beginoverlap should be like this:

void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(...)
{
ACoinPickupTutorialCharacter* Char = Cast<ACoinPickupTutorialCharacter>(OtherActor);
if(!Char)
{return;}

Char->AddCoinByValue(1) 

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

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

	Destroy();
}

Also you don’t need to show your .build.cs file because its not needed.

Hi, thank you for the advice and I fixed by follwing your comment.
However, I still have error message on CoinPickuptutorialCharacter.cpp and CoinPickupActor.cpp

CoinPickuptutorialCharacter.cpp
on line 60 ColliderComponent, and AddDynamic
ColliderComponent is not undefined

on line 133 ACPT_CoinPickupActor
name follwed by ‘::’ must be a class or namespace name

on 135 and 140 Coin
Coin is not undefined

CoinPickupActor.cpp
line 41 ACoinPickupTutorialCharacter* Char =…
ACoinPickupTutorialCharacter is undefined

line 41 ACoinPickupTutorialCharacter* Char =…
Char is undefined

line 41 OtherActor
OtherActor is undefined

I put the codes as usual and could you please make sure if I did it right or not??

CoinPickuptutorialCharacter.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "InputActionValue.h"
#include "CoinPickupTutorialCharacter.generated.h"


UCLASS(config=Game)
class ACoinPickupTutorialCharacter : public ACharacter
{
	GENERATED_BODY()

	/** Camera boom positioning the camera behind the character */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class USpringArmComponent* CameraBoom;

	/** Follow camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* FollowCamera;
	
	/** MappingContext */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputMappingContext* DefaultMappingContext;

	/** Jump Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* JumpAction;

	/** Move Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* MoveAction;

	/** Look Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* LookAction;

	//code I just added(Oct4th)
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = “Counter”)
	uint16 CoinAmount;

public:
	ACoinPickupTutorialCharacter();
	

protected:

	/** Called for movement input */
	void Move(const FInputActionValue& Value);

	/** Called for looking input */
	void Look(const FInputActionValue& Value);

	void AddCoinByValue(uint8 Value);
			

protected:
	// APawn interface
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
	
	// To add mapping context
	virtual void BeginPlay();

public:
	/** Returns CameraBoom subobject **/
	FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
	/** Returns FollowCamera subobject **/
	FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
};

CoinPickuptutorialCharacter.cpp

#include "CoinPickupTutorialCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"


//////////////////////////////////////////////////////////////////////////
// ACoinPickupTutorialCharacter

ACoinPickupTutorialCharacter::ACoinPickupTutorialCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
		
	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate

	// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
	// instead of recompiling to adjust them
	GetCharacterMovement()->JumpZVelocity = 700.f;
	GetCharacterMovement()->AirControl = 0.35f;
	GetCharacterMovement()->MaxWalkSpeed = 500.f;
	GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
	GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
}

void ACoinPickupTutorialCharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	//i just added code(Oct 4)
	ColliderComponent->OnComponentBeginOverlap.AddDynamic(
		this, &ACPT_CoinPickupActor::OnBeginOverlapComponentEvent
	);

	//Add Input Mapping Context
	if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
	{
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
		{
			Subsystem->AddMappingContext(DefaultMappingContext, 0);
		}
	}
}

//////////////////////////////////////////////////////////////////////////
// Input

void ACoinPickupTutorialCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	// Set up action bindings
	if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
		
		//Jumping
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);

		//Moving
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Move);

		//Looking
		EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Look);

	}

}

void ACoinPickupTutorialCharacter::Move(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D MovementVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	
		// get right vector 
		const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

		// add movement 
		AddMovementInput(ForwardDirection, MovementVector.Y);
		AddMovementInput(RightDirection, MovementVector.X);
	}
}

void ACoinPickupTutorialCharacter::Look(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D LookAxisVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// add yaw and pitch input to controller
		AddControllerYawInput(LookAxisVector.X);
		AddControllerPitchInput(LookAxisVector.Y);
	}
}

//i just added code(Oct 4)
void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

void ACoinPickupTutorialCharacter::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

CoinpickupActor.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "CPT_CoinPickupActor.generated.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
	);

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Counter")
	uint16 CoinAmount;

	

protected:
	//Constructor

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

	virtual void BeginPlay() override;


	
};

CoinpickupActor.h

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

	

	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(...)
{
	ACoinPickupTutorialCharacter* Char = Cast<ACoinPickupTutorialCharacter>(OtherActor);
	if (!Char)
	{
		return;
	}

	Char->AddCoinByValue(1)

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

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

	Destroy();
}

void ACPT_CoinPickupActor::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

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



You haven’t remove this in your character class. I said before to move it, probably you forgot to delete this from character class begin play.

//i just added code(Oct 4)
void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

void ACoinPickupTutorialCharacter::AddCoinByValue(uint8 Value)
{
	Coin += Value;
}

Remove the upper function (void ACPT_CoinPickupActor::AddCoinByValue(uint8 Value)), the below one is the correct one.

The Coin undefined because it is never defined. You already defined CoinAmount for that purpose but instead of using that, you use Coin which is not the correct name. You should replace the Coin variable with CoinAmount that already defined in .h.

About the other error, I believe that is related to only one error and that is ACoinPickupTutorialCharacter is undefined. It is also because you haven’t include that CoinPickupTutorialChara.h files in your PickupActor.cpp file.

I tried to include CoinPickupTutorialCharacter.h in PickupActor.cpp file but I got error message saying “cannot open source file CoinPickupTutorialCharacter.h”
Did I do wrong way??

I can’t say the proper way to include since its really depend to how your folder structure is created. Different folder structure can be handled different as well for the include.

Try to look at your folder structure, and if your character class in a different folder, include the folder first (include “MyFolder/Character.h”) or maybe you even need to include it from the base root folder from your project (include “MyProjectName/MyCharacterFolder/Character.h”)

Hi, I just solved the include CoinPickupTutorialCharacter.h. But, I still have a few error message on CoinPickupActor.cpp.

Line 39 void ACPT_CoinPickupActor::OnBeginOverlapComponentEvent(…)

Line 41 >(OtherActor)
identifier “OtherActor” is undefined

line 47 AddCoinByValue

CoinPickupTutorialCharacter.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "InputActionValue.h"
#include "CoinPickupTutorialCharacter.generated.h"


UCLASS(config=Game)
class ACoinPickupTutorialCharacter : public ACharacter
{
	GENERATED_BODY()

	/** Camera boom positioning the camera behind the character */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class USpringArmComponent* CameraBoom;

	/** Follow camera */
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	class UCameraComponent* FollowCamera;
	
	/** MappingContext */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputMappingContext* DefaultMappingContext;

	/** Jump Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* JumpAction;

	/** Move Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* MoveAction;

	/** Look Input Action */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true"))
	class UInputAction* LookAction;

	//code I just added(Oct4th)
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = “Counter”)
	uint16 CoinAmount;

public:
	ACoinPickupTutorialCharacter();
	

protected:

	/** Called for movement input */
	void Move(const FInputActionValue& Value);

	/** Called for looking input */
	void Look(const FInputActionValue& Value);

	void AddCoinByValue(uint8 Value);
			

protected:
	// APawn interface
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
	
	// To add mapping context
	virtual void BeginPlay();

public:
	/** Returns CameraBoom subobject **/
	FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
	/** Returns FollowCamera subobject **/
	FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
};


CoinPickupTutorialCharacter.cpp

#include "CoinPickupTutorialCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/CapsuleComponent.h"
#include "Components/InputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "GameFramework/Controller.h"
#include "GameFramework/SpringArmComponent.h"
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"


//////////////////////////////////////////////////////////////////////////
// ACoinPickupTutorialCharacter

ACoinPickupTutorialCharacter::ACoinPickupTutorialCharacter()
{
	// Set size for collision capsule
	GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
		
	// Don't rotate when the controller rotates. Let that just affect the camera.
	bUseControllerRotationPitch = false;
	bUseControllerRotationYaw = false;
	bUseControllerRotationRoll = false;

	// Configure character movement
	GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...	
	GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f); // ...at this rotation rate

	// Note: For faster iteration times these variables, and many more, can be tweaked in the Character Blueprint
	// instead of recompiling to adjust them
	GetCharacterMovement()->JumpZVelocity = 700.f;
	GetCharacterMovement()->AirControl = 0.35f;
	GetCharacterMovement()->MaxWalkSpeed = 500.f;
	GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
	GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;

	// Create a camera boom (pulls in towards the player if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character	
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
	FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm

	// Note: The skeletal mesh and anim blueprint references on the Mesh component (inherited from Character) 
	// are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++)
}

void ACoinPickupTutorialCharacter::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

	//Add Input Mapping Context
	if (APlayerController* PlayerController = Cast<APlayerController>(Controller))
	{
		if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerController->GetLocalPlayer()))
		{
			Subsystem->AddMappingContext(DefaultMappingContext, 0);
		}
	}
}

//////////////////////////////////////////////////////////////////////////
// Input

void ACoinPickupTutorialCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
	// Set up action bindings
	if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent)) {
		
		//Jumping
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
		EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);

		//Moving
		EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Move);

		//Looking
		EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &ACoinPickupTutorialCharacter::Look);

	}

}

void ACoinPickupTutorialCharacter::Move(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D MovementVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// find out which way is forward
		const FRotator Rotation = Controller->GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// get forward vector
		const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
	
		// get right vector 
		const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

		// add movement 
		AddMovementInput(ForwardDirection, MovementVector.Y);
		AddMovementInput(RightDirection, MovementVector.X);
	}
}

void ACoinPickupTutorialCharacter::Look(const FInputActionValue& Value)
{
	// input is a Vector2D
	FVector2D LookAxisVector = Value.Get<FVector2D>();

	if (Controller != nullptr)
	{
		// add yaw and pitch input to controller
		AddControllerYawInput(LookAxisVector.X);
		AddControllerPitchInput(LookAxisVector.Y);
	}
}

//i just added code(Oct 4)
void ACoinPickupTutorialCharacter::AddCoinByValue(uint8 Value)
{
	CoinAmount += Value;
}

CPT_CoinPickupActor.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "NiagaraFunctionLibrary.h"
#include "NiagaraComponent.h"
#include "CPT_CoinPickupActor.generated.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
	);

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Counter")
	uint16 CoinAmount;

	

protected:
	//Constructor

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

	virtual void BeginPlay() override;


	
};

CPT_CoinPickupActor.cpp

#include "CPT_CoinPickupActor.h"
#include "CoinPickupTutorial/CoinPickupTutorialCharacter.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);

	

	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(...)
{
	ACoinPickupTutorialCharacter* Char = Cast<ACoinPickupTutorialCharacter>(OtherActor);
	if (!Char)
	{
		return;
	}

	Char->AddCoinByValue(1);

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

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

	Destroy();
}

void ACPT_CoinPickupActor::BeginPlay()
{
	// Call the base class  
	Super::BeginPlay();

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



You should not replace the parameters of OnBeginOverlapComponentEvent with (…) the first time parameter already correct. I use (…) to shorten the code only.

You are right! I just copied and pasted what you told me.
But I still have error

AddCoinByValue is inaccessible.

yes, you should be more careful when copy pasting a code. Inaccessible mean the function you want to call, is not set to public so other class can’t call it. To make it accessible, just go to your ACoinPickupTutorialCharacter.h, and look for that function (The addcoin one), move the function to the public section of that class.