Lecture 58 - I've been bamboozled. (Pointers)

Hey everyone, first post on the new forums, Just wondering if you guys can help me out.

I studied pointers after the pointer video, and I thought it was going well, however I can’t seem to figure out what GetOwner is doing in line 22.

Why don’t we just point straight to GetName?
And, if I’m going to be honest while I’m here, why are we using pointers to get the name? Surely there’s an easier way.

I can’t seem to grasp why the code is written the way it is, and I was wondering if you guys could help me out.

So GetOwner() would return an AActor pointer, then AActor would have a function called GetName that would return an FString.

Though since GetOwner() returns a pointer to an AActor you can’t just use the dot operator like you previously did to access it’s members since the pointer is just a memory address, so in order to access the methods you need to derefernce it first for example *(GetOwner()).GetName() would be a way in which to do that, derefence the returned pointer then access the method or you could use the arrow operator which is a shorthand for doing just that. GetOwner()->GetName()

Just to add a little to the answer @DanM provided.

You asked why you can’t point straight to GetName(). This is because that line of code falls within the scope of the UPositionReport class, so your log message would probably say something like LogTemp:Warning: PositionReport is at location xxx

Because you will be attaching the PositionReport as a component of some other object such as the table or chair in that level, you need to call the GetOwner() method first to obtain a pointer to the owning object, then in turn call that object’s GetName() to produce a more helpful log message like LogTemp:Warning: MyChair is at location xxx

Hope that helps.