Skip to content

Plugin hotreload

Mikulas Florek edited this page Jul 8, 2024 · 6 revisions

See also LiveCode plugin.

Watch it on YouTube

Plugins in form od dynamic libraries can be hot-reloaded from Studio.

Steps to enable hotreload using Visual Studio:

  1. create a separate solution for the plugin. Example of a genie file for such plugin:

    	function copyPDA(config)
    		configuration { config }
    			prebuildcommands {
    				[[if EXIST "$(SolutionDir)bin\]]..config..[[\Hunter.pda" ( move /Y "$(SolutionDir)bin\]]..config..[[\Hunter.pda" "$(SolutionDir)bin\]]..config..[[\Hunter.pdb" )]],
    			}
    			
    			postbuildcommands {
    				[[move /Y "$(SolutionDir)bin\]]..config..[[\Hunter.pdb" "$(SolutionDir)bin\]]..config..[[\Hunter.pda"]],
    			}
    		configuration {}
    	end
    
    	dofile("../lumixengine/projects/plugin.lua")
    
    	bootstrapPlugin("Hunter")
    		files { 
    			"src/**.cpp",
    			"src/**.h",
    			"genie.lua"
    		}
    		links { "renderer", "editor" }
    		includedirs { "src", }
    		defines { "BUILDING_GAME" }
    		useLua()
    		includedirs { "../LumixEngine/external/lua/include", "../LumixEngine/external/bgfx/include" }
    		defaultConfigurations("tmp/vs2017/bin/")
    
    		copyPDA("Debug")
    		copyPDA("RelWithDebInfo")
    
    
  2. Compile Lumix Studio and the plugin

  3. Run Lumix Studio and pass the path to the plugin's library to studio as argument

    	studio.exe -plugin=c:\path\to\library.dll
    
  4. Make a change in the plugin and recompile it

  5. Lumix Studio automatically reloads the plugin

Note: Recompilation of the plugin sometimes fails because Visual Studio's debugger locks some files. If this happens detach the debugger first before recompiling the plugin.

When reloading a plugin, IScene::beforeReload is called on scene of the reloaded plugin and then the scene is removed and destroyed. After that the plugin's library is unloaded and the new one is loaded. New scene is created with the new plugin and IScene::afterReload is called.

Clone this wiki locally