Is it possible to have a script be attached to all instances of a certain node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

For example, this script extends the WindowDialog class


extends WindowDialog

var c_node = null

func _ready():
	connect("about_to_show", self, "black_backdrop")
	connect("popup_hide", self, "black_backdrop_remove")
	c_node = get_tree().get_current_scene()

 
func black_backdrop():
	GF.PlayTween({node = c_node, type = "set_opacity", from = 1, to = 0.5, seconds = 0.2, tween1 = 1, tween2 = 2})
	print("Modal is about to be shown")
	
	
func black_backdrop_remove():
	GF.PlayTween({node = c_node, type = "set_opacity", from = 0.5, to = 1, seconds = 0.2, tween1 = 1, tween2 = 2})
	print("Modal is removed")

And I am using it as a Autoload Singleton

My question is, when I create a new WindowDialog on any scene, it’s not extending it unless I attach it this script.

I am trying to attach or extend the WindowDialog class globally wherever I use a WindowDialog node in any scene, is that possible?

:bust_in_silhouette: Reply From: volzhs

Save WindowDialog with script to file and use instance scene instead of adding WindowDialog

Hmm. A sub scene basically? Will try this method, thanks!

wombatTurkey | 2016-05-23 14:20