FastScriptReload
FastScriptReload copied to clipboard
Add support to reload modules with Unity's IsExternalInit workaround to C# records
Unity has limited support to C# records and init only setters, but Unity documentation suggests to manually declare IsExternalInit class: https://docs.unity3d.com/2021.2/Documentation/Manual/CSharpCompiler.html
We use this approach in project and it works, but FastScriptReload fails to reload such modules, outputs such errors:
046412b42d9540adb22c28aa3d99dce9.SourceCodeCombined.cs(26,25): error CS0518: Predefined type 'System.Runtime.CompilerServices.IsExternalInit' is not defined or imported
Looks like it is possible to use same approach (adding IsExternalInit class) with temporary files compilation. Is there a possibility to reload such code?
Hi, I'm not quite sure, never worked with records.
If you can add an small example to recreate then I may be able to help.
Well, related is an issue with records indeed, does not seem to add a patch id on the class name. Init syntax can be replaced with this syntax btw.
Could it work with records in the end or should we take into account it won't in the shortcoming ? We started to move things into records because of the added sugar on copy ctors/parameter delcaration/init etc
public record AttackScorePosition(IReadOnlyList<AttackRangeResults> Results, Optional<PathResult> OptPath, int Score) : IScore<CharacterPosition, int>, IHasSkillResult
{
/// <summary>
/// Attack score without result
/// </summary>
public AttackScorePosition__Patched_() : this(new List<AttackRangeResults>(),Optional<PathResult>.Empty() , 0)
{
}
Also, it seems that it is not an issue with records themselves but with those using the shortcut syntax, like the one above.