UGameplayStatics::GetPlayerController will not take GetWorld()

I am trying to get a reference to the player character using UGameplayStatics::GetPlayerController(GetWorld(), 0), but I get an error under GetWorld() saying “argument of type UWorld* is incompatible with parameter of type const UObject*”

However, everywhere online I’ve seen this does not show an error. My code is:

void AMageDeflectionPrimeProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
// Only add impulse and destroy projectile if we hit a physics
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && OtherComp->IsSimulatingPhysics())
{
	AMageDeflectionPrimeCharacter* player = Cast<AMageDeflectionPrimeCharacter>(UGameplayStatics::GetPlayerController(GetWorld(), 0));
	Destroy();
}
else if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL) && !OtherComp->IsSimulatingPhysics())
{
	bounces++;
	if (bounces >= maxBounces)
		Destroy();
}
}

Does anyone know why this is happening for me even though this code apparently works in general? And how I would fix it?

1 Like

Aaand I have solved my own problem. I needed to include

#include “Engine/World.h”

Just in case anyone else has this problem in the future.

1 Like