Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Implement 'on_hot_reload' function for mods #602

Open
chudders1231 opened this issue Jul 28, 2024 · 3 comments
Open

[Suggestion] Implement 'on_hot_reload' function for mods #602

chudders1231 opened this issue Jul 28, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@chudders1231
Copy link

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.

@chudders1231 chudders1231 changed the title [Suggestions] Hot reload event [Suggestion] Hot reload event Jul 28, 2024
@UE4SS
Copy link
Collaborator

UE4SS commented Jul 28, 2024

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.

@chudders1231
Copy link
Author

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.

@UE4SS UE4SS added the enhancement New feature or request label Jul 29, 2024
@UE4SS UE4SS changed the title [Suggestion] Hot reload event [Suggestion] Implement 'on_hot_reload' global function for Lua mods Aug 5, 2024
@UE4SS UE4SS changed the title [Suggestion] Implement 'on_hot_reload' global function for Lua mods [Suggestion] Implement 'on_hot_reload' global function for mods Aug 5, 2024
@UE4SS UE4SS changed the title [Suggestion] Implement 'on_hot_reload' global function for mods [Suggestion] Implement 'on_hot_reload' function for mods Aug 5, 2024
@inkydragon
Copy link

A workaround: maybe you need ModRef:SetSharedVariable/GetSharedVariable

Warning: These variables do not get reset when hot-reloading.

—— https://docs.ue4ss.com/lua-api/classes/mod.html?highlight=ModRef#getsharedvariablestring-variablename

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants