Multiple scripts in a Node #10211
Replies: 6 comments 2 replies
-
Like when you click on the script button on a node maybe have a dropdown to show like all the scripts that the node uses? |
Beta Was this translation helpful? Give feedback.
-
Attaching multiple scripts is enormously more difficult code wise Related, for making dividing up code and functionality, see: You can also extend scripts to divide up code, but you might also need to re-evaluate your code if your scripts grow that large, for example identify code duplication, for example put the same code being used multiple times in a new function, or in some helper class, etc. |
Beta Was this translation helpful? Give feedback.
-
As someone who came to Godot from Unity and its component system, I think I understand what you're getting at. My understanding has come to be that the "one script per node" concept is part of Godot's core architecture and design philosophy. I think the "Godot-ey" equivalent of what you're looking for would be to create child nodes that contain the sub-behaviors you're thinking of. The parent can handle coordination between each of its child nodes when necessary. |
Beta Was this translation helpful? Give feedback.
-
Separation into 2 scripts is enough: tool script and runtime script. Tool script for editor and runtime script for game, instead of @tool mode and runtime is_editor_hint assertion. |
Beta Was this translation helpful? Give feedback.
-
This got me wondering about the possibility of scripts being able to specify/require a certain type of parent or owner node. For example, in a current project of mine, I have a state machine node with state children. Currently, I do something like Something like: # state_machine.gd
class_name StateMachine
extends Node # state.gd
class_name State
extends Node
child_of StateMachine
func _ready():
get_parent() # <-- guaranteed to be a StateMachine, autocomplete/type checking verified That being said, I dunno how difficult it would be to implement, and/or if the benefits of it would outweigh the development difficulties. Just thought it'd be something to bring up as an idea, in the spirit of this conversation :) |
Beta Was this translation helpful? Give feedback.
-
I used different nodes with names like Attack System or Movement System or Camera System and have a script accessing variables from the player and it kinda works but It's still kind of annoying |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a script that is 1000 lines long, and I would really like to just have separate scripts to be much cleaner instead of having to scroll to far to find a variable, like Idk why godot is like this
Beta Was this translation helpful? Give feedback.
All reactions