4.16.0+ component generator regression

Should be working with the latest compiler too. Have you tried again?

Not working with 3.0.6:

export class AccessorTest extends Behaviour {

    @serializable()
    public publicFoo: number = 123;

    @serializable()
    private privateFoo: number = 456;

    @serializable()
    public set bar(v: number) { this._bar = v; }
    public get bar(): number { return this._bar; }
    private _bar: number = 789;
}
	public partial class AccessorTest : UnityEngine.MonoBehaviour
	{
		public System.Single @publicFoo = 123;
	}

pre-3.0.0:

	public partial class AccessorTest : UnityEngine.MonoBehaviour
	{
		public float @publicFoo = 123f;
		public float @bar;
	}

(The private field with @serializable was just for fun :wink: )

Hi, sorry I missed that the compiler tests where still running using typescript 4.x not 5.

The latest version will now output

// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly

#pragma warning disable

namespace Needle.Typescript.GeneratedComponents
{
	public partial class AccessorTest : UnityEngine.MonoBehaviour
	{
		public System.Single @publicFoo = 123f;
		public System.Single @bar;
	}
}

// NEEDLE_CODEGEN_END

Yes, can confirm, thanks!

Regarding different visibilities I noticed some inconsistencies between field and accessor serialization:

import { Behaviour, serializable } from "@needle-tools/engine";

export class AccessorTest extends Behaviour {

    @serializable()
    public publicFoo: number = 123;

    @serializable()
    private privateFoo: number = 456;

    @serializable()
    protected protectedFoo: number = 456;

    @serializable() 
    private set publicBar(v: number) { this._bar = v; }
    private get publicBar(): number { return this._bar; }
    private _bar: number = 789;

    @serializable() 
    protected set protectedBar(v: number) { this._bar = v; }
    protected get protectedBar(): number { return this._bar; }

    @serializable() 
    private set privateBar(v: number) { this._bar = v; }
    private get privateBar(): number { return this._bar; }
}
	public partial class AccessorTest : UnityEngine.MonoBehaviour
	{
		public float @publicFoo = 123f;
		[UnityEngine.SerializeField]
		private float @publicBar;
		[UnityEngine.SerializeField]
		protected float @protectedBar;
		[UnityEngine.SerializeField]
		private float @privateBar;
	}

If possible, I’d rather have them both behave the same way without needing the clunkier // @serializeField.

I think you’re right (at least it should be consistent).

@serializable does now emit the field (both private and public) except if it’s ALSO decorated with the // @nonSerialized comment.

1 Like

Hi @Marcel_Wiessler1 , something new popping up now (3.0.13 of the compgen package). Don’t know if it was a problem before as only touched scripts get regenerated:

onEditorModification(_: EditorModification): void | undefined | boolean {...}

becomes

public bool onEditorModification(object @_) {}

which is not compilable:

error CS0161: 'AnchoredButton.onEditorModification(object)': not all code paths return a value

Decorating with // @nonSerialized does nothing here.

After fixing it, other similar cases pop up. I really need a way to have public methods in web-land which do not get forced counterparts in unity-land.

Hello @krizzl0r what other similar cases do you get?

Will look at the error above, @nonSerialized should really avoid this, sorry. Will add tests for these cases

Edit:

There’s actually a test in place for the nonSerialized case you described above and it passes. Maybe there’s something else causing this in your case? Do you have more context?

A fix for the return type should be available soon.

  it('should skip method marked with @nonSerialized', () => {
    compareCodegenWithDefaultContext("nonserialized on method",
      // INPUT
      `export class MyComponent extends Behaviour {
    // @nonSerialized
    onEditorModification(modification: EditorModification): void | undefined | boolean { return false; }
}
`,
      // EXPECTED
      `public partial class MyComponent : UnityEngine.MonoBehaviour
	{
	}`
    );
  });

Sorry, nothing out of the ordinary and with 3.0.15 it works both now as intended :person_shrugging: Thanks!

1 Like

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.