不太理解 "Can not serialize …… ” 这个报错,求高手指点。

情况说明:
我创建了一个cc.Class类,如下:

var AAA = cc.Class({

statics:{
    instance:null
},
properties:
{
    tester:"我是AAA的一个属性"
},

});

AAA .instance = new AAA();

module.exports = AAA ;

在BBB类里使用它,如下

var AAA = require("AAA ");
console.log(AAA.instance.tester);

一开始它能运行
但是刷新了一次之后编译器报错:

Can not serialize 'BBB.AAA ’ because the specified type is anonymous, please provide a class name or set the ‘serializable’ attribute of 'BBB.AAA ’ to ‘false’.

BBB 挂在一个预制物体上。

看起来好像是要求我给一个类名,或 把序列设置为“false”

请问我该怎么做?在哪里给类名?在哪里设置serializable = false ?

你要保存到场景文件中吗?要的话 AAA 加上 name

var AAA = cc.Class({
    name: 'AAA',
    ... 
})
2赞

好的,谢谢。

请问TS要怎么实现, 我现在想自定义一个 BasePrefab继承cc.prefab, 但是这个自定义类不能在编辑器中挂载预制体。报的错跟题主一样。

@ccclass(‘类名’)

2赞