Here’s a simple Gem that adds a new EBUS that lets you run console commands from Lua.
PRO TIP: You can use a console command to exit game mode in the editor. Very handy when you have a Quit button in your UI that you want to exit the game in the launcher but only leave game mode in the editor. Just execute the following command from Lua when the button is pressed: “py general.exit_game_mode()”
4817-luaconsolegem-ly19.zip (17.3 KB)luaconsolegem-ly19.zip
To install:
-
Extract the zip to your dev/Gems folder
-
Open ProjectConfigurator, enable this Gem in your project and save
-
In a command window run lmbr_waf configure
-
Build your project from Visual Studio or the command line
Example usage: -
Create an entity that has a Lua script component.
-
Select the dev/Gems/LuaConsole/scripts/components/LuaConsoleTestComponent.lua file
-
A Command property will appear in the component’s properties after you select this file
-
Enter a console command to run or leave the example one
-
Run the game and the command will be executed immediately
LuaConsoleTestComponent.lua
local LuaConsole = {
Properties = {
Command = { default="r_displayInfo 2", description="Console command to run automatically"}
}
}
function LuaConsole:OnActivate()
-- run the console command
LuaConsoleRequestBus.Broadcast.ExecuteConsoleString(self.Properties.Command)
end
return LuaConsole