How can i use the same function in different scripts?

Godot Version



How can i use the same function without having to copypaste it everytime i put it in a script or change something about it

You could use static functions:

where do i create a static function and how do i call it in a script?

Create a utility script, e.g. and give it a class_name:

class_name Utilities

Then, add your shared functions to it, e.g.

static func shared_function(example_arg: float) -> void:

From the other scripts, you can call the shared_function:


There are some alternative approaches too, it really depends on your project. Give that a go.