Open luckyabsoluter opened 3 months ago
Please test in 4.2.2, or 4.3, 4.2.1 is no longer supported and this might have been fixed.
Sounds related to:
Which was fixed in 4.3 by:
Reproduced on v4.3.stable.official [77dcf97d8]
can_instantiate()
. See also #64065.I believe it would be more intuitive if, instead of the current error message stating that the new()
method doesn't exist, the error could explicitly indicate that the script cannot be instantiated due to errors in the script. This would make it clearer that the issue lies with the script's validity rather than suggesting that the new()
method is missing from a seemingly valid GDScript
object.
Such an error message would better guide users toward understanding the root cause of the issue and encourage the use of can_instantiate()
to validate scripts before attempting to instantiate them.
Thank you for your input and the reference to the can_instantiate()
method.
This response was generated with the assistance of GPT.
Tested versions
v4.2.1.stable.official [b09f793f5] v4.3.stable.official [77dcf97d8]
System information
Godot v4.2.1.stable
Issue description
When loading a
.gd
script using theload()
function in Godot, the function returns aGDScript
object even if there are parsing errors in the script. This is unexpected because:GDScript
object should always have anew()
method.loaded.has_method("new")
returningtrue
, callingloaded.new()
results in the error:This issue is problematic because there's no clear way to detect or handle this scenario programmatically. Even with parse errors, the script loads and appears valid according to the checks. The only way to detect that the script has issues is by using
loaded.reload()
, which returns a non-zero value if errors are present. However, relying on this method for error detection is not intuitive or well-documented.Expected behavior:
Steps to reproduce
Here’s an example of the code and its output in both normal and error scenarios:
Code:
Output with a valid script:
Output with a script containing parse errors:
Error encountered:
Steps to reproduce:
Minimal reproduction project (MRP)
gdscript load issue project.zip