godotengine / godotengine/godot

C# tool scripts without a parameterless constructor crash the editor on build

Open
#87,147 1 comment 0 reactions 0 assignees View on GitHub
discussion needs testing topic:dotnet topic:editor
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in 4.2.1.stable

### System information

Godot v4.2.1.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated Radeon RX 580 Series (Advanced Micro Devices, Inc.; 31.0.21905.1001) - AMD Ryzen 7 2700X Eight-Core Processor (16 Threads)

### Issue description

## Problem
If you instantiate a C# tool script that has no parameter-less constructor in a scene and then rebuild, the editor will crash.

This can happen if you instantiate the tool script through another tool script.

## Expected behavior
I expect the editor not to crash and instead output an error message telling that it couldn't instantiate the culprit script.

AFAIK C# tool scripts always need a parameter-less constructor so I don't expect the editor to be able to reload such scripts. However the editor shouldn't crash because of such scripts.

### Steps to reproduce

1. open `scene.tscn` in the MRP
2. build a first time
3. reload the editor (an instance of a tool script without a parameter-less ctor will be added to the scene)
4. change the source of any C# script (e.g. add a newline)
5. rebuild
6. the editor crashes

### Minimal reproduction project (MRP)

[MRP.zip](https://github.com/godotengine/godot/files/13928273/MRP.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.