I am modifying the shooter game.
I wrote this declaration in the ShooterCharacter.H File
UFUNCTION(BlueprintImplementableEvent)
void SSCustomDamage();
and then I made a function call to it here in the ShooterCharacter.CPP File
float AShooterCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser)
{
AShooterPlayerController* MyPC = Cast<AShooterPlayerController>(Controller);
SSCustomDamage();
if (MyPC && MyPC->HasGodMode())
{
return 0.f;
}
if (Health <= 0.f)
{
return 0.f;
}
// Modify based on game rules.
AShooterGameMode* const Game = GetWorld()->GetAuthGameMode<AShooterGameMode>();
Damage = Game ? Game->ModifyDamage(Damage, this, DamageEvent, EventInstigator, DamageCauser) : 0.f;
const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
if (ActualDamage > 0.f)
{
Health -= ActualDamage;
if (Health <= 0)
{
Die(ActualDamage, DamageEvent, EventInstigator, DamageCauser);
}
else
{
PlayHit(ActualDamage, DamageEvent, EventInstigator ? EventInstigator->GetPawn() : NULL, DamageCauser);
}
MakeNoise(1.0f, EventInstigator ? EventInstigator->GetPawn() : this);
}
return ActualDamage;
}
Then I did the rest in BluePrint. Everything works fine and does exactly what I want it to do in the editor.
It builds fine with no errors or warnings in visual studio.
Those 3 lines of code are all that I changed 2 lines for the function declaration and 1 line to call to it.
But I am getting LNK 2019 error when I Package the project, and I get these warnings in my Unreal Logs
that point back to my function:
MainFrameActions: Packaging (Windows (64-bit)): UnrealBuildTool: Creating library C:\Users\Colorado\Documents\Unreal Projects\ShooterGame\Survival-Shooter\Binaries\Win64\ShooterGame.lib and object C:\Users\Colorado\Documents\Unreal Projects\ShooterGame\Survival-Shooter\Binaries\Win64\ShooterGame.exp
MainFrameActions: Packaging (Windows (64-bit)): UnrealBuildTool: Module.ShooterGame.cpp.obj : error LNK2019: unresolved external symbol “public: void __cdecl AShooterCharacter::SSCustomDamage(void)” (?SSCustomDamage@AShooterCharacter@@QEAAXXZ) referenced in function “public: virtual float __cdecl AShoot
MainFrameActions: Packaging (Windows (64-bit)): erCharacter::TakeDamage(float,struct FDamageEvent const &,class AController *,class AActor *)” (?TakeDamage@AShooterCharacter@@UEAAMMAEBUFDamageEvent@@PEAVAController@@PEAVAActor@@@Z)
MainFrameActions: Packaging (Windows (64-bit)): UnrealBuildTool: C:\Users\Colorado\Documents\Unreal Projects\ShooterGame\Survival-Shooter\Binaries\Win64\ShooterGame.exe : fatal error LNK1120: 1 unresolved externals
MainFrameActions: Packaging (Windows (64-bit)): UnrealBuildTool: -------- End Detailed Actions Stats -----------------------------------------------------------
MainFrameActions: Packaging (Windows (64-bit)): UnrealBuildTool: ERROR: UBT ERROR: Failed to produce item: C:\Users\Colorado\Documents\Unreal Projects\ShooterGame\Survival-Shooter\Binaries\Win64\ShooterGame.exe
Did I do something wrong?
Am I supposed to write more code to make a Blueprint Implementable Function?