I have a damage interface that takes in a pointer to an actor, damage and a float for force:
UFUNCTION(BlueprintNativeEvent)
void RecieveDamage(AActor* otherActor, float damage, float force);
When called from any class to my player class, the function works and I receive no issues. However, when all of the same classes call on my enemy class the enemy class otherActor is received as a nullptr and crashes the game. I am not calling them any differently and I cannot figure out why the enemy class is only receiving null pointers from the method call.
Here is the Player Function:
void ACutiePlayer_Character::RecieveDamage_Implementation(AActor* otherActor, float damage, float force)
{
//otherActor isValid here
if (!Invincible)
{
//Reduce Health
Health -= damage;
IsDamaged = true;
Invincible = true;
this->DisableInput(PlayerCon);
GetCharacterMovement()->StopMovementImmediately();
FVector LineOfContact = otherActor->GetActorLocation() - this->GetActorLocation();
LineOfContact.Normalize();
FVector LaunchForce = LineOfContact * -force;
GetCharacterMovement()->AddImpulse(LaunchForce, true);
}
}
And Here is the enemy function:
void AEnemy_Basic::RecieveDamage_Implementation(AActor* otherActor, float damage, float force)
{
//otherActor is not valid here
//Reduce Health
Health -= damage;
IsDamaged = true;
//Call Method to disrupt movement.
GetCharacterMovement()->StopMovementImmediately();
if (otherActor != nullptr) //Not Passing
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("ActorExists!")));
}
if (IsValid(otherActor)) //Not Passing
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("ActorExists!")));
FVector LineOfContact = otherActor->GetActorLocation() - this->GetActorLocation();
LineOfContact.Normalize(); //Crashes Engine
FVector LaunchForce = LineOfContact * -force;
GetCharacterMovement()->AddImpulse(LaunchForce, true);
}
else // Always Passing
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Does not Exist!")));
}
}