Invoke a function on tool mode script reload

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CakeLover

How do I invoke a function every time the Script is loaded or reloaded?

tool

func _reload():
    print("Changes have been made and saved! Script has been reloaded")

func _load():
    print("Project was just opened! Script has been loaded")
:bust_in_silhouette: Reply From: rossunger

Depends on what you mean by load/reload!

Your best bets are the _init function and the _enter_tree
Init is called when you first instance that script, and enter tree is called every time you add it to the tree.

How are you reloading? The easiest ways would be to have your load function happen on init, and then your reload function to be called manually when you decide to reload the script

But if by reload you’re also including the next time the project is opened, then you should probably save a global variable somewhere that tells if you if it’s been loaded before and check if it’s true.