IssueRaiser

Make the C# tool script reloading process easier to work with

### Describe the project you are working on A colony survival/resource management game in C# with a lot of custom tooling ### Describe the problem or limitation you are having in your project The way data is reloaded into C# tool scripts after an assembly reload (e.g. after a recompilation) currently causes a lot of small annoyances that need to be worked around. Also, the specifics of data reloading are not documented which makes the behavior hard to predict unless you read the Godot source code. I'll describe the problems I've experienced one by one. ### 1. The parameter-less constructor of tool scripts is called after every compilation Every time you recompile your project, already instantiated tool scripts' parameter-less constructor is called. This is ok if your script doesn't do anything in its constructor or just sets initial data that doesn't rely on anything. However, if your constructor has side-effects, e.g. like adding a child node, this becomes a problem. ```csharp [Tool] public partial class MyToolScript : Node { public MyToolScript() { // This will be executed after every recompilation, probably not what you want/expect AddChild(new Node()); } } ``` The solution here is to never have side-effects in your parameter-less constructor. However, it can be limiting and it's easy to forget. ### 2. Tool scripts that don't have a parameter-less constructor can't be reloaded If your tool script doesn't have a parameter-less construct

Posted by ershn on Feb 1, 2024, 2:37 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

ux (Other)

Make the C# tool script reloading process easier to work with

ershnFeb 1, 2024, 2:37 AM

### Describe the project you are working on A colony survival/resource management game in C# with a lot of custom tooling ### Describe the problem or limitation you are having in your project The way data is reloaded into C# tool scripts after an assembly reload (e.g. after a recompilation) currently causes a lot of small annoyances that need to be worked around. Also, the specifics of data reloading are not documented which makes the behavior hard to predict unless you read the Godot source code. I'll describe the problems I've experienced one by one. ### 1. The parameter-less constructor of tool scripts is called after every compilation Every time you recompile your project, already instantiated tool scripts' parameter-less constructor is called. This is ok if your script doesn't do anything in its constructor or just sets initial data that doesn't rely on anything. However, if your constructor has side-effects, e.g. like adding a child node, this becomes a problem. ```csharp [Tool] public partial class MyToolScript : Node { public MyToolScript() { // This will be executed after every recompilation, probably not what you want/expect AddChild(new Node()); } } ``` The solution here is to never have side-effects in your parameter-less constructor. However, it can be limiting and it's easy to forget. ### 2. Tool scripts that don't have a parameter-less constructor can't be reloaded If your tool script doesn't have a parameter-less construct

Comments (0)

No comments yet. Start the discussion.

Comment on this issue