GetOwner() Problem

Here is my code for PositionReport.cpp, the BeginPlay() part.

void UPositionReport::BeginPlay()
{
Super::BeginPlay();

FString ObjectName  = GetOwner()->GetName();
FString ObjectPos = GetOwner()->GetTransform().GetLocation().ToString();
UE_LOG(LogTemp, Warning, TEXT("%s is at %s"), *ObjectName, *ObjectPos);

}

GetOwner() is marked as an error, and while building, it also says that one build has failed. However, in Unreal, the code works. The error reads as: Pointer to Incomplete Class Type Is Not Allowed. I found GetOwner definition:

FORCEINLINE_DEBUGGABLE AActor* UActorComponent::GetOwner() const
{
#if WITH_EDITOR
// During undo/redo the cached owner is unreliable so just used GetTypedOuter
if (bCanUseCachedOwner)
{
checkSlow(OwnerPrivate == GetActorOwnerNoninline()); // verify cached value is correct
return OwnerPrivate;
}
else
{
return GetActorOwnerNoninline();
}
#else
checkSlow(OwnerPrivate == GetActorOwnerNoninline()); // verify cached value is correct
return OwnerPrivate;
#endif
}

Can someone please tell me what is wrong? It’s really bugging me. Thanks!

P.S. Sorry if it looks weird, this is my first post, and I do not know how to put all the code together.

Hey Samuel,

ChrisVomRhein posted a possible solution for this in the discussion of lecture 62.


He included “Engine.h” in his cpp files.
I had the problem as well and it helped me out.
However in my case it also increased the building time significantly

1 Like

Thanks a lot, it really helped me. You were right about the build time though, but it’s Summer and I can spare a few extra minutes :wink:

Privacy & Terms