Including the same code snippet in every entity

Godot Version



Hi, I’m new to programming so forgive the simple question.

I’m writing code for a pause menu to pop up on screen whenever the “Events” singleton script sends the game_paused signal.

In the Events script i have this code:

signal game_paused(bool)

func _unhandled_input(event: InputEvent) -> void:
	if Input.is_action_just_pressed("pause"):

And I wrote this code for entities, so that they are paused when the pause menu shows up:

func _ready() -> void:

func _on_events_game_paused(pause: bool) -> void:
	if pause == true:
	elif pause == false:

The problem is: I’m having to paste this second code snippet in every entity (player, enemies, enemy spawner, etc)

Is there a way to turn that code in a “standalone script” and “include” the script at the start of another script?

Like you would #include <stdio.h> in C for example?


a better way is to use pause_mode which is already in godot
and then you just set what you want and what you don’t want to have in the pause process

I see, so I’m reinventing the wheel here, lol

Thanks, i’ll check it out

Find out how to correctly pause the game along with the shader animations.

Thank you, I watched it