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