godot-console
godot-console copied to clipboard
[Suggestion] Reset to default
Something like Console.reset_to_default() to remove all commands besides the default ones.
My player character is creating console commands, but when I switch levels or go to the menu, all the commands break because they can't find a reference. Also, in the menu, commands relating to the player or gameplay shouldn't work anyway, and it's a lot to remember to remove each command manually when the scene changes, and adding a call for each new command I create.
I'm not sure if this is really required feature but I would like to hear what others (lets hope there are others)) have to say.
Generally I would suggest removing commands yourself by subscribing to node destruct signal since it is faster, it should make code clearer that when you register command and remove it on node removal.
But if you absolutely need to remove everything besides default commands I can come up with this quick solution:
const CommandCollection = preload('res://addons/quentincaffeino-console/src/Command/CommandCollection.gd')
func remove_custom_commands():
Console.get_command_service()._command_collection = CommandCollection.new()
Console.BaseCommands.new(Console)
(haven't actually tested this code, wrote it right here in gh issues)
But this solution might stop working anytime since it's using private interfaces so I highly suggest considering the first solution.
I think this function would be useful. (If it is not too complicated to implement)
@andersmmg, maybe you can use the function remove_command Doc link to delete your custom commands? It requires the command name, so maybe you can store your custom commands' names in an array then for each entry of that array call remove_command to reset to default.
However, a function to reset could be pretty useful.