ToonTanks 152 compile errors

Hey there, I’ve been following along with the ToonTanks class but have ran into an issue that I cannot seem to figure out:

the longer errors being:

...\ToonTanks\Components\HealthComponent.cpp(24) : error C2672: 'TSparseDynamicDelegate<FTakeAnyDamageSignature_MCSignature,AActor,FTakeAnyDamageSignatureInfoGetter>::__Internal_AddDynamic': no matching overloaded function found
...\ToonTanks\Components\HealthComponent.cpp(24) : error C2780: 'void TSparseDynamicDelegate<FTakeAnyDamageSignature_MCSignature,AActor,FTakeAnyDamageSignatureInfoGetter>::__Internal_AddDynamic(UserClass *,TBaseDynamicDelegate<FWeakObjectPtr,RetValType,AActor *,float,const UDamageType *,AController *,AActor *>::TMethodPtrResolver<UserClass>::FMethodPtr,FName)': expects 3 arguments - 2 provided

This is the HealthCOmponent.cpp code:

// Fill out your copyright notice in the Description page of Project Settings.


#include "HealthComponent.h"
#include "ToonTanks/GameModes/TankGameModeBase.h"
#include "Kismet/GameplayStatics.h"
#include "Math/UnrealMathUtility.h"

// Sets default values
AHealthComponent::AHealthComponent()
{
 	// 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;

}

// Called when the game starts or when spawned
void AHealthComponent::BeginPlay()
{
	Super::BeginPlay();
	
	Health = DefaultHealth;
	GameModeRef = Cast<ATankGameModeBase>(UGameplayStatics::GetGameMode(GetWorld()));
	GetOwner()->OnTakeAnyDamage.AddDynamic(this, &UHealthComponent::TakeDamage);
}

void AHealthComponent::TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatedBy, AActor* DamageCauser) 
{
	if(Damage == 0 || Health <= 0)
	{
		return;
	}

	Health Fmath::Clamp(Health - Damage, 0.0f, DefaultHealth);

	if(Health <= 0)
	{
		if(GameModeRef)
		{
			GameModeRef->ActorDied(GetOwner());
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("Health Component has no reference to the GameMode"));
		}
	}
}

And the .h file:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "HealthComponent.generated.h"

class ATankGameModeBase;

UCLASS()
class TOONTANKS_API AHealthComponent : public AActor
{
	GENERATED_BODY()

private:
	UPROPERTY(EditAnywhere)
	float DefaultHealth = 100.f;
	float Health = 0.0f;

	ATankGameModeBase* GameModeRef;
	
public:	
	// Sets default values for this actor's properties
	AHealthComponent();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	UFUNCTION()
	void TakeDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatedBy, AActor* DamageCauser);

};

Can anyone help me with finding the issue? Please let me know if more info or code is required.

class TOONTANKS_API AHealthComponent : public AActor

You have created an Actor not an ActorComponent. I’d suggest you create a new class derived from the correct type.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms