I created a C++ code in Component with Variable and assigned Owner of Component to the Variable. Also I created logs that prints the Variable value’s name (i.e. Owner name). It works perfectly in my output logs but it doesn’t work in my game when I try to get Owner name in my blueprint to Print String it.
Here is my Component constructor with logs:
PrimaryComponentTick.bCanEverTick = true;
AActor* OwnerActor = GetOwner();
if (OwnerActor)
{
FString OwnerName = OwnerActor->GetName();
UClass* OwnerClass = OwnerActor->GetClass();
FString OwnerClassName = OwnerClass ? OwnerClass->GetName() : TEXT("Unknown Class");
UE_LOG(LogTemp, Warning, TEXT("Owner Name: %s, Owner Class: %s"), *OwnerName, *OwnerClassName);
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Owner is nullptr"));
}
ACharacter* OwnerCharacter = Cast<ACharacter>(OwnerActor);
if (OwnerCharacter)
{
Owner2DCharacter = Cast<AGGE2DCharacter>(OwnerCharacter);
if (Owner2DCharacter)
{
UE_LOG(LogTemp, Warning, TEXT("CAST IS SUCCESSFUL! Owner Character Name: %s"), *Owner2DCharacter->GetName());
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Owner Is Not Of Type AGGE2DCharacter"));
}
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Owner Is Not Of Type ACharacter Or Is Nullptr"));
}
if (IsValid(Owner2DCharacter))
{
UE_LOG(LogTemp, Warning, TEXT("Owner2DCharacter is invalid or has been deleted"));
}
