Could someone explain this please

void UPositionReport::BeginPlay()
{
	Super::BeginPlay();
	FString ObjectName = GetOwner()->GetName();
	FString ObjectPos = GetOwner()->GetTransform().GetLocation().ToString();
	UE_LOG(LogTemp, Warning, TEXT(" %s is located at %s"), *ObjectName, *ObjectPos);	
}

I’m a little confused. Is ObjectName and ObjectPos a variable or the name of the pointer? I’m not sure as the use is identicle to assigning a variable but as the name of a pointer it’s the only way that *ObjectName and ObjectPos makes sense to me. In my mind I think
FString ObjectName* = GetOwner()->GetName();
makes more sense to me so I’m confused. Should I just think of it as anytime you use a -> to drill down you give the pointer a name then use
PointerName to access it?

Sorry I’m new to programming so I’m trying to wrap my head around this very important topic and I learn best if I understand why something is then just remembering a seemingly arbitrary rule. If someone could just break down what is going on here as far as the pointer logic is concerned I would be greatful. Thanks!

ObjectName and ObjectPos are FStrings though the TEXT macro doesn’t take FStrings it takes a const TCHAR * and FString has overloaded the * operator to get that

/**
 * Get pointer to the string
 *
 * @Return Pointer to Array of TCHAR if Num, otherwise the empty string
 */
FORCEINLINE const TCHAR* operator*() const
{
    return Data.Num() ? Data.GetData() : TEXT("");
}

std::string basically has the same functionality (with const char* instead of const TCHAR*) through the .data() function.

Also if GetName() did return a pointer to an FString then this code is wrong for declaring a pointer

It should be FString* ObjectName

Privacy & Terms