Topic was automatically imported from the old Question2Answer platform.
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")
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.