Godot Version
4.5.1.stable
Question
I’d like to be able to force the user to restart their editor after installing a plugin. I spent a while yesterday looking for this functionality. Anyone know how to do that? I want to add it to the _enable_plugin() and _disable_plugin() for a plugin script.
Bonus solution, how to refresh the editor and reflect changes made to the InputMap after running this code:
ProjectSettings.set_setting("input/" + action, input_map)
ProjectSettings.save()
That would be a more elegant solution.
EditorInterface::restart_editor()
The bonus thing: Put actions into project settings and into InputMap singleton.
2 Likes
So I ended up doing EditorInterface.restart_editor(). When run in the plugin, even if passing save = true it pops up a dialog asking if you want to save, not save or cancel the reboot.
I tried out the second recommendation @normalized and it half worked. The actions worked without a reboot, but they didn’t show up in the InputMap interface in Project Settings until the editor was rebooted.
I decided to leave it in, because it doesn’t hurt anything.
static func add(action: StringName, ...events: Array) -> void:
var input_map = {
"deadzone": 0.2,
"events": []
}
InputMap.add_action(action)
for event in events:
if event is float:
input_map["deadzone"] = event
InputMap.action_set_deadzone(action, event)
elif event is InputEvent:
InputMap.action_add_event(action, event)
input_map["events"].append(event)
ProjectSettings.set_setting("input/" + action, input_map)
ProjectSettings.save()
static func remove(action: StringName) -> void:
InputMap.erase_action(action)
ProjectSettings.set_setting("input/" + action, null)
ProjectSettings.save()
The dialog won’t appear if all scenes and all scripts are saved.
Looks like the save flag for restart_editor() saves the scenes but I don’t think it saves the scripts. Afaik “Save All Scripts” functionality is not exposed to scripting.
You’ll have to save them manually although even that might not work to get rid of the dialog if the save status is maintained internally by the script editor. Still worth a try. Open scripts can be obtained by calling EditorInterface.get_script_editor().get_open_scripts(). Iterate through that and save them one by one.
You can peek into source code to see what’s involved when “Save All Script” is issued from the menu: ScriptEditor::save_all_scripts()
That all said, I’d never force the restart on users without prompting for permission.
2 Likes
Agreed. I was going to create a popup but the one provided felt close enough for now.
The weird thing is when I run it, there shouldn’t be anything NOT saved. So I’m not sure that it matters what it saves.
I did consider just not forcing the reboot and leaving the warning there and letting people figure it out. I decided to enable the restart and see how much it annoyed me while I use it.
I don’t get any popups when all scripts are saved. It just blindly restarts. There may be something other than scripts though.
1 Like