Open chudders1231 opened 4 months ago
Anything executed at file scope of main.lua (i.e. anything not in a function) is executed immediately upon the loading or reloading of a mod. You didn't give a lot of information but hopefully this answer was helpful, otherwise provide more information about what you want.
yeah so i guess this is only important in a dev environment.
for example in my init function i will cache a load of info, and say i want to get the local player character but that info is not available on the main menu.
so if i was to call the init outside of ServerAcknowledgePossession
, that will throw errors in the main menu right and means that i would need to remember to remove those sorts of functions when publishing. But if there was an event that is fired when hot reloading, the transition from dev to production would be really nice.
it is obviously nothing important but would be a nice QoL feature for me personally.
A workaround: maybe you need ModRef:SetSharedVariable/GetSharedVariable
Warning: These variables do not get reset when hot-reloading.
local function AfterInitGameStateHook()
-- TODO
end
-- The game has been initialised
local ModGameStart = ModRef:GetSharedVariable("ModGameStart")
if ModGameStart and type(ModGameStart) == "boolean" then
print("Mod hot-reloading.\n")
AfterInitGameStateHook()
else
print("First Start Game.\n")
-- Called after AGameModeBase::InitGameState
RegisterInitGameStatePostHook(function(GameState)
if ModRef:GetSharedVariable("ModGameStart") then
return
end
ModRef:SetSharedVariable("ModGameStart", true)
print("AfterInitGameStateHook\n")
AfterInitGameStateHook()
end)
end
for debugging purposes it would be nice to have an event that we could hook into to execute initialisation for example that would otherwise be called in
ServerAcknowledgePossession
which is my preferred initialisation event.