handzlikchris / handzlikchris/FastScriptReload

Static fields in changed code are lost upon reload

Ouverte
#110 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
feature
Langage dominant
C#
Étoiles
2.2k
Forks
167
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Reproduisez le problème dans Unity avec une classe statique contenant un champ Material obtenu par réflexion, puis modifiez DrawReticleCircle et observez le journal OnScriptHotReloadNoInstance. Examinez la gestion du hot-reload pour les champs statiques et déterminez si la valeur perdue est attendue ou s’il s’agit d’un défaut. La tâche est considérée comme terminée lorsque le comportement est corrigé ou que sa limitation est clairement documentée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
csharp, unity
Domaine
game-dev, tooling
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.