Skip to content

Commit

Permalink
feat: UEHelpers: Rework GetPlayerController() to search through all A…
Browse files Browse the repository at this point in the history
…Controller for first PlayerController

feat: UEHelpers: Remove fallback to GameViewportClient in GetWorld(), since the new GetPlayerController() should always return a valid controller
  • Loading branch information
igromanru committed Sep 8, 2024
1 parent c824c42 commit a82bd54
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions assets/Mods/shared/UEHelpers/UEHelpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ local PlayerControllerCache = RemoteObject:new() ---@cast PlayerControllerCache
function UEHelpers.GetPlayerController()
if PlayerControllerCache:IsValid() then return PlayerControllerCache end

local GameInstance = UEHelpers.GetGameInstance()
if GameInstance:IsValid() and #GameInstance.LocalPlayers > 0 then
local localPlayer = GameInstance.LocalPlayers[1]
if localPlayer:IsValid() then
PlayerControllerCache = localPlayer.PlayerController
local Controllers = FindAllOf("Controller") ---@type AController[]?
if Controllers then
for _, Controller in ipairs(Controllers) do
if Controller:IsValid() and Controller:IsPlayerController() then
PlayerControllerCache = Controller
break
end
end
end

Expand Down Expand Up @@ -111,13 +113,8 @@ function UEHelpers.GetWorld()
WorldCache = PlayerController:GetWorld()
return WorldCache
end
local GameViewportClient = UEHelpers.GetGameViewportClient()
if GameViewportClient:IsValid() then
WorldCache = GameViewportClient.World
return WorldCache
end

return RemoteObject:new() ---@type UWorld
return WorldCache
end

--- Returns an object that's useable with UFunctions that have a WorldContextObject param.
Expand Down

0 comments on commit a82bd54

Please sign in to comment.