-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_init with parameters breaks when used with scene tree editor #75920
Comments
You should not create node classes with required constructor parameters, they cannot be instantiated from the scene editor. Also, when adding a node from code, extends Node
class_name MyNodeClass
var param: String
static func create(p_param: String) -> MyNodeClass:
var packed_scene: PackedScene = load("res://my_node_class.tscn")
var node: MyNodeClass = packed_scene.instantiate()
node.param = p_param
return node Usage: var node := MyNodeClass.create("test")
add_child(node) Related:
I also remember that there was a proposal/comment about adding the ability to specify node/resource parameters when creating in the editor (but IMO this unnecessarily complicates things). |
It's definitely not a great thing to do, but the engine, instead of having a sensible error, will proceed without informing the user what is happening. It's failing with errors that don't give the user the information they need. Not to mention having unusual side effects. The program should not run. |
Godot version
4.0.2
System information
Windows 10
Issue description
I was exploring whether I should instantiate a number of slot node from an exported count parameter, or collect the manually added nodes in said parameter. I had created an _init function to properly initialize these slots, when my static typing seemed to hit this error.
Steps to reproduce
The problem is demonstrated in the provided project with an assert. Note that the problem goes away if there are no parameters in
_init
for thetest_class.gd
script. Additionally, a cpp exception is emitted.Minimal reproduction project
Bug_report_class_name.zip
The text was updated successfully, but these errors were encountered: