multiple scripts per node

Godot Version

4.6.2

Question

Why is godot’s multiple scripts per node feature so broken and feels not properly supported

For example I attach a script to a node then do extends right but then if I want to connect a signal to the first script I gotta detach then reattach the script connect signal then extend it again also wish it showed which scripts it had and not the latest one only (as shown in ss bottom) is there an extension of some sort that helps with these problems?

Because there is no such feature.

There are discussions about implementing such a feature or how to circumvent it, but there is no support in Godot itself.

Perhaps if you tell us why you need multiple scripts, and how you are using them we could help you find an alternate solution.

Yeah so I have 2 hands with each their scripts but the thing is they’re the same other than 1 variable so I combined them to a single script and then in their own script I overrides init to change a islefthand variable I also use this technique in my weapons and then change damage ammo count etc.

To achieve what you’re doing you should @export your variables and then adjust them in the editor. No need for multiple scripts per node.

yeah but what about custom functions that export method will work for hands ty I’m stuipd how’d I not think of that but for weapons I also wanna add a few custom overrides or even new functions also since this is a mulitiplayer game a script handles all shooting sound position logic on multiplayer if I made 10 weapons when I changed smth I’d have to change it in all of them

For cases where you’re sure you want to add custom logic you could make your base script a custom class using class_name, make your nodes of that type, and implement unique logic in their scripts.

You have a few options here. I couldn’t give you much because you still haven’t described the problem you are having in concrete details. The quality of your answer depends on the effort you put into your question, and frankly you are writing like you think we can read your mind.

Option 1 - Single Script

class_name HandControl extends XRNode3D

Enum Hand {
LEFT,
RIGHT,
}

@export hand: Hand


func _ready() -> void:
	if hand == Hand.LEFT:
		print("Left Hand")
	else:
		print("Right Hand")

Option 2 - Inheritance

class_name HandControl extends XRNode3D


func _ready() -> void:
	print("Generic Hand")
class_name LeftHandControl extends HandControl


func _ready() -> void:
	print("Left Hand")
class_name RightHandControl extends HandControl


func _ready() -> void:
	print("Right Hand")

Option 3 - Abstraction

@abstract
class_name HandControl extends XRNode3D


func _ready() -> void:
	print(get_hand())


@abstract
func get_hand() -> String
class_name LeftHandControl extends HandControl


func get_hand() -> String:
	return "Left Hand"
class_name RightHandControl extends HandControl


func get_hand() -> String:
	return "Right Hand"

yeah I already have that but like it’s just annoying that you can’t connect a signal to the first script you attached after you’Ve extended another script to the node also sometimes stuff don’t work I re do the attaching then extending and it works so that systems just all funky I was wondering since godot is open source and all maybe some1 did some helper stuff to that

I use inheritance btw

also yeah ig I’m writing it quite vaguely but I feel like this is enough information idk ig I did miss out some details and stuff sorry about that and thank you for the help btw!’

What was the question again?

This paragraph was hard to parse, but I don’t think you understand how extending scripts work. Using my above examples, I’d just do this:

class_name HandControl extends XRNode3D

signal new_signal


func _ready() -> void:
	print("Generic Hand")

Now every script extended from it can use the signal. You’re making it sound like this is not only hard to do, but impossible.

If it was enough information you’d have an answer already. @normalized and I answer questions on here every day and neither of us can figure out what your problem actually is. I thought I’d answered it and all you said was, “I use inheritance.”

Was my answer helpful? Not helpful? Answer your question? Didn’t answer your question?