How to solve " Error constructing a GDScriptInstance." in GDScript - Godot 4
Published: June 4, 2024
Last updated: June 14, 2024
- error
- GDscript
The `_create_instance: Error constructing a GDScriptInstance.` error happens when GDscript fails to construct an object for some reason.
Usually, that reason is that you have an object with an overwritten `_init()` function, like so:
extends Node
class_name YourCustomObject
_init(foo_parameter: String) -> void:
pass
And then you try to create that object in the editor's inspector. The issue here is that you can't specify the `_init` parameter values in the editor.
There's two way to solve this issue:
1. Add default values to the `_init` parameters
extends Node
class_name YourCustomObject
_init(foo_parameter: String = '') -> void:
pass
2. Remove the custom `_init` and rely on exported values instead
extends Node
class_name YourCustomObject
@export var foo_parameter: String
About the author
Hey there 👋
I'm Blaubessen, a web dev learning Godot. This website is my way of documenting my learnings, and hopefully be useful to other folks as well.
If you find mistakes, disagree with something written, or just have general feedback please feel free to leave a comment on this form!