Improve instantiating nodes in the editor with unnamed script classes #12562
harrison-munitz
started this conversation in
Editor
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Instancing nodes from scripts which include a
class_name
is very easy. You open the Create New Node window, select your class in the list, and you're done. It creates a new node, attaches the correct script to it and sets the correct base-class that your script inherits from.However, when the script doesn't include a
class_name
the process is a bit more manual. It's by no means complicated, but it has more potential for mistakes and represents a "gotcha" in the engine. Specifically, since unnamed classes don't appear in the Create New Node window, you have to make sure to manually choose the correct base-class of node to attach the script to (or remember to change it after) since adding the script will not automatically change the node's type. This can lead to all sorts of weird and undesirable behavior or more likely, instant errors and crashes.For example: If you add a
Node2D
to your scene and then give it a script which inherits fromControl
it will still be aNode2D
, but with all of the additional behavior and properties from that script. It will typically cause the game to crash as soon as the script tries to access a member or method ofControl
since it doesn't have them.I propose two different solutions, either or both would improve the user experience around unnamed classes:
Beta Was this translation helpful? Give feedback.
All reactions