Hi guys, I am just trying a call the function Death() which is located in Sentinal.cpp from Shrouded.cpp using a cast. Sentinal.h has been included within the Shrouded.cpp file. However when it is called with Sentinal->Death(); it returns null.
Any help would be appreciated, I am able to provide more if needed.
Shrouded.cpp
void AShrouded::Melee()
{
GetWorldTimerManager().SetTimer(ShroudHandle, this, &AShrouded::Unshroud, 0.1, false);
FVector Location;
FRotator Rotation;
FHitResult Hit;
FString HitActor;
GetController()->GetPlayerViewPoint(Location, Rotation);
FVector Start = Location;
FVector End = Start + (Rotation.Vector() * MeleeDistance);
FCollisionQueryParams TraceParams;
bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_Visibility, TraceParams);
if (bHit)
{
DrawDebugLine(GetWorld(), Start, End, FColor::Red, false, 2.0f);
DrawDebugBox(GetWorld(), Hit.ImpactPoint, FVector(2, 2, 2), FColor::Red, false, 2.0f);
ASentinal* Sentinal = Cast<ASentinal>(GetOwner());
if (Sentinal != nullptr)
{
Sentinal->Death();
}
else {
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("null"));
}
}
}
Sentinal.h
UFUNCTION()
void Death();
Sentinal.cpp
void ASentinal::Death()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("You killed a Sentinal"));
GetMesh()->SetAllBodiesSimulatePhysics(true);
GetMesh()->SetSimulatePhysics(true);
GetMesh()->WakeAllRigidBodies();
GetMesh()->bBlendPhysics = true;
}