Skip to content

Commit 5f431e6

Browse files
committed
perf(UEHelpers): Fast path for GetPlayerController
It now tries to get the player controller via GameInstance.LocalPlayers[0], and only falls back on the slow FindAllOf method if that fails.
1 parent 3d4fbd0 commit 5f431e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

assets/Mods/shared/UEHelpers/UEHelpers.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ end
6969
function UEHelpers.GetPlayerController()
7070
-- local Controllers = jsb.simpleBench("FindAllOf: PlayerController", FindAllOf, "PlayerController")
7171
-- Controllers = jsb.simpleBench("FindAllOf: Controller", FindAllOf, "Controller")
72+
local Players = UEHelpers.GetGameInstance().LocalPlayers
73+
if Players:IsValid() and Players:GetArrayNum() >= 1 then
74+
local FirstController = Players[1].PlayerController
75+
if FirstController:IsValid() and (FirstController.IsPlayerController and FirstController:IsPlayerController() or FirstController:IsLocalPlayerController()) then
76+
return FirstController
77+
end
78+
end
79+
7280
local Controllers = FindAllOf("PlayerController") or FindAllOf("Controller") ---@type AController[]?
7381
if Controllers then
7482
for _, Controller in ipairs(Controllers) do

0 commit comments

Comments
 (0)