handzlikchris / handzlikchris/FastScriptReload

Static fields in changed code are lost upon reload

Đang mở
#110 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
feature
Ngôn ngữ chính
C#
Star
2.2k
Fork
167
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I am not sure whether this is expected behaviour or not, but I could not find any reference in the documentation to static fields not being supported.
I am trying to reload a static class that has a static `Material` field that is assigned on startup via reflection.
The static class content looks like this:
```C#
private static Material material;

public static void DrawReticleCircle(in ReticleDrawArgs args)
{
var position = args.WorldPosition;
// ...
Graphics.DrawMesh(mesh, trs, material, 0);
}

static void OnScriptHotReloadNoInstance()
{
Debug.Log($"Post-reload, asset is {material} (null={material==null})");
}
```

After changing the contents of DrawReticleCircle, the script is reloaded but the value of `material` is lost.
The debug log reads: `Post-reload, asset is (null=True)`

I would expect for the value to be copied over, or for the new code to reference the field in the old assembly (if this is possible?).

Is this a known limitation or a bug? If it is a limitation, I think it is worth pointing out in the documentation.
Thanks.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Tái hiện vấn đề trong Unity bằng một lớp tĩnh chứa một trường Material được lấy qua reflection, sau đó chỉnh sửa DrawReticleCircle và quan sát log OnScriptHotReloadNoInstance. Đọc phần xử lý hot-reload đối với các trường tĩnh và xác định liệu giá trị bị mất có phải là hành vi được mong đợi hay là một lỗi. Được xem là hoàn tất khi hành vi đã được khắc phục hoặc giới hạn của nó được ghi rõ trong tài liệu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
csharp, unity
Lĩnh vực
game-dev, tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.