Serializable number problem

Hello, I’m working on scripts which move the camera around characters.
For it, I need to specify the position of the camera in relation to the character.

But I have a problem, I use (as the documentation says), my field like this :

    @serializable()
    CameraOffsetX?: number = 5;
    @serializable()
    CameraOffsetY?: number = 12;
    @serializable()
    CameraOffsetZ?: number = 5;

And after give the component to my character, it looks like this (after changing the value of my fields to adapt the position of the camera) :
[view image]

But the value in my component on unity are not used, it’s always 5/12/5 on all of my characters (one script by character to adapt each position).

How could I fix that ?

Original Post on Discord

by user 224464722878005248

Changed the channel name: Serializable number problem

by user 224464722878005248

Thanks, reproduces here :slightly_smiling_face:

workaround is to lowercase the field names

e.g. “cameraOffsetX”

Oh, thanks !

by user 224464722878005248

I added a warning to the deserialization. Currently all fields must start lowercase

image.png

Thanks !
And, what about the serizalisation of string ?

by user 224464722878005248

by user 224464722878005248

The fields don’t appear

by user 224464722878005248

Can you send the code ? I try

import { serializable } from "@needle-tools/engine";
import { Behaviour, GameObject } from "@needle-tools/engine/engine-components/Component";
import { Object3D} from "three";
import { CameraControl } from "./CameraControl";

export class ManageSelecting extends Behaviour
{
    // @serializable(Light)
    // ourPointLight? : Light;
    @serializable(Object3D)
    ourName?: Object3D
    @serializable(Object3D)
    ourLookAt?: Object3D
    @serializable(GameObject)
    levelBoundary?: GameObject

    @serializable()
    cameraOffsetX?: number = 5;
    @serializable()
    cameraOffsetY?: number = 12;
    @serializable()
    cameraOffsetZ?: number = 5;

    @serializable(String)
    nomDuPersonnage?: String = "default"
    @serializable(String)
    texteDuPersonnage?: String = "Texte du personnage"

    returnBtn: any;
    cameraControl: any;

    start() {
        if(this.ourName != undefined) {
            this.ourName.visible = false;
        }

        if(this.ourLookAt != null) {
            this.originalLookAt[0] = this.ourLookAt.position.x;
            this.originalLookAt[1] = this.ourLookAt.position.y;
            this.originalLookAt[2] = this.ourLookAt.position.z;
        }
        this.cameraControl = this.levelBoundary?.getComponent(CameraControl)
    }

by user 224464722878005248

    update(){
        let ray = this.context.physics.raycast()
        let isHovered = false;

        for(let i = 0; i < ray.length; i += 1) {
            if(ray[i].object.parent != null) {
                if(ray[i].object.parent?.name == this.gameObject.name) {
                    // console.log("found : ", this.gameObject.name)
                    isHovered = true;
                }
            }   
        }
        // console.log(this.ourPointLight)
        if(isHovered) {
            if(this.ourName != undefined) {
                this.ourName.visible = true
            }
            if(this.context.input.getPointerDown(0)){
                let namePanel = document.getElementById("namePanel")
                let textPanel = document.getElementById("textPanel")

                //@ts-ignore
                namePanel.innerHTML = this.nomDuPersonnage
                //@ts-ignore
                textPanel.innerHTML = this.texteDuPersonnage

                this.cameraControl.zoomCamera(this.gameObject.position.x, 
                    this.gameObject.position.y, 
                    this.gameObject.position.z, 
                    this.cameraOffsetX, this.cameraOffsetY, this.cameraOffsetZ)
                
            }
        }
        
    }

}

by user 224464722878005248

ah you need to use lowercase “string”

    @serializable(String)
    nomDuPersonnage?: string = "default"
    @serializable(String)
    texteDuPersonnage?: string = "Texte du personnage" 

and you can leave @serializable empty for strings, bools and number types

Okay, thanks !

by user 224464722878005248


    @serializable()
    nomDuPersonnage?: string = "default"
    @serializable()
    texteDuPersonnage?: string = "Texte du personnage" 

like this (but doesnt hurt if you add String too, it’s just not necessary for the builtin primitives that javascript has)