GetWorld() vs GetOwner()

Hi, I had a go myself at getting the viewpoint and came up with several alternatives:

	GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorEyesViewPoint(Location, Rotation);
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(Location, Rotation);
	GetOwner()->GetActorEyesViewPoint(Location, Rotation);

The one that I selected was the GetOwner()->GetActorEyesViewPoint(Location, Rotation) - This for me seemed more appropriate as the GrabberComponent is designed to be a component of the PlayerPawn and therefore the GetOwner() seemed more intuitive and then you don’t need to include the world.h file.

Which of these approaches is more efficient?

Well using GetOwner would make more sense as you’ve pointed out. In terms of efficiency I highly doubt it be a noticeable difference if you were to profile it.

The world stores the list of player controllers so you’re just accessing the first element of that array.
Controllers store the pawn it controls so really the only difference is two extra levels of indirection.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms