creator 3.x get set 无法保存的问题

版本:Creator 3.3.2Creator 3.4.0

脚本如下:

import { _decorator, Component, Node, CCString } from "cc";
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = login_logic
 * DateTime = Tue Dec 28 2021 10:45:48 GMT+0800 (中国标准时间)
 * Author = o7ezxnerb
 * FileBasename = login-logic.ts
 * FileBasenameNoExtension = login-logic
 * URL = db://assets/login-logic.ts
 * ManualUrl = https://docs.cocos.com/creator/3.4/manual/zh/
 *
 */

@ccclass("LoginLogic")
export class LoginLogic extends Component {
    @property
    private bundleName: string = "";

    private url: string = "";

    @property({ type: CCString })
    get link() {
        return this.url;
    }
    set link(value: string) {
        this.url = value;
    }

    start() {
        console.log(this.bundleName);
        console.log(this.url);
    }
}

在节点中设置了 link 的值,刷新一下场景或者预制体,会导致 link 的值丢失。

这是故意什么设计还是我的脚本有问题导致的?

加一个条件吧,value 为空,就不要赋值了

    set link(value: string) {
        this.url = value;
    }

谢谢老哥!

我看了下文档,发现是我的用法错了。

脚本进阶 · Cocos Creator

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。