0 votes

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


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

func _load():
    print("Project was just opened! Script has been loaded")
Godot version 3.4
in Engine by (46 points)

1 Answer

0 votes

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.

by (1,260 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.