Can't access function in another class C++

Chances are that Sentinal is not owning Shrouded, reason why your GetOwner() doesn’t return what you expect.
If I understand correctly a Sentinal is what you’re trying to hit; try to cast Hit.Actor instead.
Hope that helps.

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;
	
}

Is Shrouded a component of Sentinal? I assume GetOwner() doesn’t return what you expect it to return, and that’s why casting fails.

No they’re two seperate classes. Yeah I’m not sure if GetOwner was the play Death() is just a simple function in Sentinal.

I’m not sure because im not using the standard on hit but rather a line trace to determine whether or not it has hit another character.

You sent me on the right track fraps! I had to case Hit.GetActor() instead.
Here’s the code:

	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>(Hit.GetActor());
		if (Sentinal != nullptr)
		{
			Sentinal->Death();
		}
		else {
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, TEXT("null"));
		}
		

	}