Accessing pointers, syntax confusion

Hi,

I hoped to get some explanation in this video about the difference between:

HitActor->GetNa…

and for example

GetOwner()->FindCom…

Why is there sometimes the brackets before the arrow and sometimes not, and more importantly how can I learn to find out what I would need?

One is a function the other is a variable.


HitActor is a AActor pointer variable we created.

AActor* HitActor = Hit.GetActor();

Hit has a function called GetActor which returns an AActor* and we use that to initialise our variable HitActor.

1 Like

Ah ok, so business as usual basically.

If I want to point to a method I use brackets, if I want to point to variable, I just use the arrow without brackets

Not to. We aren’t pointing to a variable per se or pointing to a function.

GetOwner() is a function that returns an AActor pointer so then we would use the arrow operator to access the returrned AActor's methods, like GetName() which is a AActor function which returns an FString(not a pointer) so we can call it’s methods like ToUpper() using the dot operator since the FString isn’t a pointer, i.e. GetOwner()->GetName().ToUpper()

Okay I think this makes sense.

I am having a little trouble using the right words/phrases, but I feel like I understand the differences.

Thank you for the explanations!

Privacy & Terms