How do I turn a script on/off from another script in GDScript?

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

I want to disable a script from another script. What is the best way to create a toggle for this?

:bust_in_silhouette: Reply From: SQBX

If you only care about making it so that the _process function(s) are not called:

whatever_script.set_process(false) # Disable target_node's process
whatever_script.set_physics_process(false) # Disable target_node's physics_process

If you disable other functions, make a disabled variable:

var disabled = false

And before each function you want to disable, write:

if disabled:

If you want some functions to still work, don’t include the above code in them.

Then, you can set disabled to true or false from other scripts

whatever_script.disabled = true # Disabled whatever_script