That is what I was wondering. It was talking about using something that does not belong to the class.
Here it is cleaned up of my messy notes, hopefully I didn’t delete anything in the process:
ProjectileBase.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ProjectileBase.generated.h"
class UProjectileMovementComponent;
UCLASS()
class TOONTANKS_API AProjectileBase : public AActor
{
GENERATED_BODY()
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UProjectileMovementComponent* ProjectileMovement;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UStaticMeshComponent* ProjectileMesh;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true"))
UParticleSystemComponent* ParticleTrail;
UPROPERTY(EditDefaultsOnly, Category = "Damage")
TSubclassOf<UDamageType> DamageType;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Move", meta = (AllowPrivateAccess = "true"))
float MovementSpeed = 1300;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Damage", meta = (AllowPrivateAccess = "true"))
float Damage = 50;
UPROPERTY(EditAnywhere, Category = "Effects")
UParticleSystem* HitParticle;
UPROPERTY(EditAnywhere, Category = "Effects")
USoundBase* HitSound;
UPROPERTY(EditAnywhere, Category = "Effects")
USoundBase* LaunchSound;
UPROPERTY(EditAnywhere, Category = "Effects")
TSubclassOf<UCameraShakeBase> HitShake;
UFUNCTION()
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
public:
AProjectileBase();
protected:
virtual void BeginPlay() override;
};
ProjectileBase.cpp
#include "ProjectileBase.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystemComponent.h"
AProjectileBase::AProjectileBase()
{
PrimaryActorTick.bCanEverTick = false;
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Projectile Mesh"));//Visual
RootComponent = ProjectileMesh;
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
ProjectileMovement->InitialSpeed = MovementSpeed;
ProjectileMovement->MaxSpeed = MovementSpeed;
ParticleTrail = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("Partical Trial"));
ParticleTrail->SetupAttachment(RootComponent);
InitialLifeSpan = 3.0f;
}
void AProjectileBase::BeginPlay()
{
Super::BeginPlay();
ProjectileMesh->OnComponentHit.AddDynamic(this, &AProjectileBase::OnHit);
UGameplayStatics::PlaySoundAtLocation(this, LaunchSound, GetActorLocation());
}
void AProjectileBase::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
AActor* MyOwner = GetOwner();
if(!MyOwner){return;}
if (OtherActor && OtherActor != this && OtherActor != MyOwner)
{
UGameplayStatics::ApplyDamage(
OtherActor,
Damage,
MyOwner->GetInstigatorController(),
this,
DamageType
);
UGameplayStatics::SpawnEmitterAtLocation(this, HitParticle, GetActorLocation());
UGameplayStatics::PlaySoundAtLocation(this, HitSound, GetActorLocation());
GetWorld()->GetFirstPlayerController()->ClientStartCameraShake(HitShake);
Destroy();
}
}