Description
Godot version
Any 4.x version
Issue description
Assembly reloading can fail for various reasons, usually because a library used in tools code is not compatible with assembly unloading.
After unloading has failed, C# scripts will be unavailable until the editor is restarted (in rare cases it may be possible to complete the unloading by re-building assemblies after some time).
If assembly unloading fails for your project check Microsoft's troubleshooting instructions and ensure that you are not using one of the libraries known to be incompatible:
- Json.Net is not currently unloadability-friendly. JamesNK/Newtonsoft.Json#2414
- System.Text.Json should support unloadable assemblies correctly dotnet/runtime#65323
If you know of additional libraries that cause issues, please leave a comment.
If your code doesn't use any libraries, doesn't violate any guidelines and you believe unloading is blocked by godot, please open a new issue. Already reported causes are:
- C# Script Registration that use Generics can error out in the ScriptManagerBridge #79519
- C# assigning a default value to an exported custom resource property will cause error #80175 1
- Capturing a variable in a Callable prevents assembly unloading #81903
- Change order of operation for C# types reloading #90837 1
Minimal reproduction project & Cleanup example
using Godot;
using System;
[Tool]
public partial class UnloadingIssuesSample : Node
{
public override void _Ready()
{
// block unloading with a strong handle
var handle = System.Runtime.InteropServices.GCHandle.Alloc(this);
// register cleanup code to prevent unloading issues
System.Runtime.Loader.AssemblyLoadContext.GetLoadContext(System.Reflection.Assembly.GetExecutingAssembly()).Unloading += alc =>
{
// handle.Free();
};
}
}
Footnotes
Metadata
Metadata
Assignees
Type
Projects
Status
No status