when adding // @serializeField to a field all other private fields of the class get translated to c# as well and decorated with [SerializeField].
It even adds the attribute to the commented-out fields where translation went wrong, e.g.:
[UnityEngine.SerializeField]
// private MyClass | null @_myClassInstance; â Could not resolve C# type
[UnityEngine.SerializeField]
private bool @foo;
...
which then results in error CS0579: Duplicate 'UnityEngine.SerializeField' attribute.
Side note: Please consider unifying the command naming, just add aliases. I always have trouble recalling which is which and thereâs no intellisense helping me
Hi krizzl0r, thanks for the detailed report and feedback!
The issue youâre seeingâwhere using // @serializeField ends up tagging all private fields (including commentedâout ones) with [SerializeField] so that you get a duplicate attribute error in the generated C#âseems to be caused by the parser not properly filtering out fields that shouldnât be serialized. In other words, the translation process is applying the decoration to every field it finds (even those weâd expect to be skipped, like commented out ones), which is why youâre seeing error CS0579.
A couple of workarounds you might consider are:
âą Explicitly mark fields you do not want serialized with the exclusion command (// @nonSerialized) so theyâre filtered out during translation.
âą Remove or temporarily delete commented-out code from the file if itâs not meant to be processed.
Regarding your side note about unifying the command names (like @generate-component, @dont-generate-component, @serializeField, and @nonSerialized), this feedback is very valuable. We realize that remembering which command to use can be a challenge, and adding aliases or enhanced intellisense support would indeed help streamline the workflow. This is something weâll look into for future updates.
If youâre not already on the latest Needle Engine version, please consider updating or even creating a minimal reproducible example on StackBlitz via Needle-engine - Vite Template (duplicated) - StackBlitz. Also, if youâre using Unity integration, using âCopy Project Info Into Clipboardâ and filing a bug report might speed up resolution.
Hope this helps, and thanks again for your input! Let me know if you have further questions or need additional details.
1 replies left - Become PRO for more replies. thread_qioStzacoBDvmCtCYdqmA8lt Reply to this post directly if you need further help (bottom right button)
public partial class ComponentCompilerBug : UnityEngine.MonoBehaviour
{
public UnityEngine.GameObject @publicObject;
}
As expected only the public field is translated. (One could argue _privateObject should be translated too as it is decorated with @serializable() though)
Hi, the issue will be fixed with the next update (4.5.8) of the Unity package (which will update the compiler package to 1.12). This will include some of your other suggestions e.g. // @type object will serialize non-component classes
Iâve added your examples to the compiler tests, thanks for that.