FindComponentByClass()

Hi, I did things a little differently in the challenge for the error log, instead of:
GetOwner()->GetName()

I did:

GetWorld()->GetFirstPlayerController()->GetPawn()->GetName();

Seems to work, but I see that it’s a longer, more roundabout way. Is the GetOwner version better then?

I would say yes, the first way is better, since instead of relying on the world and its methods you’re going directly to the owner, which also obviously saves a few calls.

An example of “Bottom Up” vs “Top Down” searching.
Bottom up works when you can locate the “lowest” object easily …(and since objects in unreal have Owners and you are able to use GetOwner() very easily to do this)

Top Down , I suppose , is for when the “lowest” object you are looking for is NOT so easily located…since in the earlier case, you don’t have any code objects executing against the pawn, you can’t (at that stage) call GetOwner(), therefore to find the pawn you need to look down from the top to see what it is called.

At least that’s what I think!

Privacy & Terms