"Could not resolve C# type" error

Should have been fixed in 3.28.3-pre

Just to briefly respond to your earlier point - I did try adding “@serializable()” and “@serializable(RacerEntry)” but neither worked.

Engine version is 3.27.4-pre

by user 259070246382469121

Ah okay, thats great. Ill update so, I had avoided updating as naturally there is a risk other things break. Just for clarity, as I am a noob with Needle (and web dev in general), in this case, do I need the serializable tag on the RacerEntry class in the typescript class?

by user 259070246382469121

No, you don’t, but you should have serializable attributes on your fields (racerTransform etc.) so that they are correctly typed

If you don’t want to upgrade you should also be able to use the // @type RacerEntry decorator as workaround (goes above public racers)

Also there should be a @serializable attribute on the fields inside RaceOrderManager that you want to be serialized.

Made a quick example that I’ll likely add to our samples as well.

C#, RaceCar.cs:

using System;
using UnityEngine;

namespace Needle.Samples
{
    [Serializable]
    public class RaceCar
    {
        public string name;
        public GameObject model;
        public float speed;
    }
}

Here’s the typescript side, RaceCar.ts:

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

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

class RaceCar {
    @serializable(AssetReference)
    model: AssetReference;

    @serializable()
    speed: number = 0;

    @serializable()
    name: string = "";
}

export class RaceCarManager extends Behaviour {     

    @serializable(RaceCar)
    cars: RaceCar[]; 
    
    async start() {
        console.log("Race Cars", this.cars);

        // create cars and make them go brrrrr
        for (let i = 0; i < this.cars.length; i++) {
            const car = this.cars[i];
            const carObject = await car.model.instantiate();
            if (!carObject) throw new Error("Car model not found");
            
            carObject.worldPosition = new Vector3(i * 2.5, 0, 0);
            
            // if there's already a RaceCarMovement component, use it, otherwise add one
            const carMovement = carObject.getOrAddComponent(RaceCarMovement)!;
            carMovement.speed = car.speed;

            // add to the scene
            this.context.scene.add(carObject);
        }
    }
}

export class RaceCarMovement extends Behaviour {
    @serializable()
    speed: number = 0;

    update() {
        this.gameObject.transform.position.z += this.speed * this.context.time.deltaTime;
    }
}

Awesome @herbst🌵 thank you for this. Just out at the moment so will upgrade the project version and reference your script here shortly.

by user 259070246382469121

It was serializing the individual attributes that worked a charm. Ive also upgraded. Thank you for your help.

by user 259070246382469121

Wonderful - thanks for letting me know!