FYI, looking at UE code, the pawn is a member variable of the PlayerController
, so that part it free. The harder part is getting the controller. And for that, UE is only iterating through a couple arrays of player controllers, in the worst case, and usually it is the first item of the first array.
I didn’t benchmark either, but short of nasty surprises, it would require calling GetPlayerPawn
several thousands of time per tick, if not millions, for it to become a problem.
I wouldn’t even be surprised if calling GetPlayerPawn
was faster than having a member variable, just because that PlayerController array might stay hot in the CPU cache (since it’s regularly needed by various different objects), while the AIController would get cold (since it’s only need when processing that AI) and would need to be fetched again.