Serialized custom class variable not showing up in Editor

Hi, I was playing around with needle and ts but had this issue. This hideObjects is visible in the unity editor but sequenceList is not. I don’t know what I am doing wrong. Any help is appreciated. Thanks
This is my ts,

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

// Documentation → https://docs.needle.tools/scripting

class Sequence{
    @serializable()
    public stepObjects : GameObject[] = [];
    @serializable()
    public hideObjects2 : GameObject[] = [];
}
export class TestManager extends Behaviour {

    @serializable()
    hideObjects?: GameObject[];

    @serializable(Sequence)
    public sequenceList?: Sequence[];
    
    start() {
    }
}
and this is the generated codegen 
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly

#pragma warning disable

namespace Needle.Typescript.GeneratedComponents
{
	public partial class TestManager : UnityEngine.MonoBehaviour
	{
		public UnityEngine.GameObject[] @hideObjects;
		public Needle.Typescript.GeneratedComponents.Sequence[] @sequenceList;
		public void start(){}
	}
}

// NEEDLE_CODEGEN_END

Hi Ashok,

The issue you’re encountering where sequenceList is not showing up in the Unity editor could be due to a couple of reasons:

  1. Decorator Usage: Ensure that you use the @serializable() decorator correctly. In your code, you’re declaring sequenceList with @serializable(Sequence); make sure that Sequence is being recognized properly as a serializable type. This implies that Sequence should also be correctly set up as a class with serializable properties.

  2. Unity Editor Limitations: The Unity editor sometimes does not serialize certain properties or collections properly, particularly when using complex types or custom classes. In this case, ensure that the Sequence class itself is properly defined, particularly ensuring that both stepObjects and hideObjects2 are decorated for serialization if needed.

Here’s a slight modification to your Sequence class that improves clarity:

class Sequence {
    @serializable() //. Ensure that stepObjects is properly serializable
    public stepObjects: GameObject[] = [];

    @serializable() //.Make sure this is also serializable if needed.
    public hideObjects2: GameObject[] = [];
}
  1. Editor Scripts: You may lack a proper custom inspector or editor script that enables the properties to be visible. If they are complex types, you might want to define a custom editor for TestManager or Sequence.

  2. Automatic Undo/Redo: Sometimes, even if the properties are serializable, Unity may require you to force validation to see updates in the Inspector. Implement an OnValidate method to trigger property updates in your component.

If you’ve checked the above and still have issues, you might want to share the exact versions of Needle Engine and Unity you are using. It would help in providing a more tailored solution.

Feel free to ask if you need further assistance!

1 replies left - Get a PRO license for more AI replies.
thread_BsKBEk7ut0BBoDj2T3dxwvBM
Reply to this message to continue the conversation

Hi,

the Sequence class is not a component which means it will not automatically generated by our Component generator. You can simply write the C# code in Unity (as you would with a regular “non Behaviour” class)

The sample you posted is a bit confusing - it looks like you have public Needle.Typescript.GeneratedComponents.Sequence[] @sequenceList; as a C# component but in your typescript you use it as a regular class

Here’s an example in the docs for your case: Scripting Examples | Needle Engine Documentation

Hi,
Now I added my class in c# too as in the provided documentation. Like this,

using UnityEngine;
using System;


[Serializable]
public class Sequence
{
    public GameObject[] stepObjects;
    public GameObject[] hideObjects;
}
but I still can't see my custom class in Unity editor, this is the generated codegen for this ts. As you can see for some reason it consider my class as visualScripting. 
// NEEDLE_CODEGEN_START
// auto generated code - do not edit directly

#pragma warning disable

namespace Needle.Typescript.GeneratedComponents
{
	public partial class TestManager : UnityEngine.MonoBehaviour
	{
		public UnityEngine.GameObject[] @seqenceHideObjects = new UnityEngine.GameObject[]{ };
		public Unity.VisualScripting.Sequence[] @sequenceList = new Unity.VisualScripting.Sequence[]{ };
		public void start(){}
	}
}

// NEEDLE_CODEGEN_END

Hi, ok now the issue is that there are multiple Sequence classes in your Unity project so the compiler initially doesn’t know which one is the right one - you can easily solve this by annotating your TS code with the correct namespace+class - see the second example here Automatic Component Generation | Needle Engine Documentation

Yeah, thanks. I removed the visual scripting package and it solved the issue.