From b47690ff342e67d537a2008a1e4e5969a7bb797c Mon Sep 17 00:00:00 2001 From: igromanru Date: Tue, 26 Nov 2024 10:35:55 +0100 Subject: [PATCH] refactor(UEHelpers): In GetWorld() get UWorld from PlayerController, fallback to GameInstance if a PlayerController doesn't exist --- assets/Mods/shared/UEHelpers/UEHelpers.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/assets/Mods/shared/UEHelpers/UEHelpers.lua b/assets/Mods/shared/UEHelpers/UEHelpers.lua index 359c7d64..c7f408b9 100644 --- a/assets/Mods/shared/UEHelpers/UEHelpers.lua +++ b/assets/Mods/shared/UEHelpers/UEHelpers.lua @@ -102,13 +102,13 @@ local WorldCache = CreateInvalidObject() ---@cast WorldCache UWorld function UEHelpers.GetWorld() if WorldCache:IsValid() then return WorldCache end - local GameInstance = UEHelpers.GetGameInstance() - if GameInstance:IsValid() then - WorldCache = GameInstance:GetWorld() - else -- Worst case fallback, usaully should never happen - local PlayerController = UEHelpers.GetPlayerController() - if PlayerController:IsValid() then - WorldCache = PlayerController:GetWorld() + local PlayerController = UEHelpers.GetPlayerController() + if PlayerController:IsValid() then + WorldCache = PlayerController:GetWorld() + else + local GameInstance = UEHelpers.GetGameInstance() + if GameInstance:IsValid() then + WorldCache = GameInstance:GetWorld() end end return WorldCache