Cocos Creator- TypeScript: extends cc.Component does not work properly

Hello.

I am using cocos creator based on typescript.
Occasionally, the property values set in the scene disappear, so I figured out why.
As a result, if the class inheriting from cc.Component is inherited again, the added property will not work properly.

The steps are as follows.

  1. ‘SuperClass’ inherits from cc.Component, and ‘ChildClass’ inherits from ‘SuperClass’.
export default class SuperClass extends cc.Component {

    @property({
        default: "hello"
    })
    text: string = 'hello';

 ... ...

import SuperClass from "./SuperClass";
export default class ChildClass extends SuperClass {

    @property({
        default: ""
    })
    childText: string = '';
  1. I use both ‘SuperClass’ and ‘ChildClass’ in the same scene, the ‘childText’ property of the ‘ChildClass’ will not work properly.
    error_typescript

  2. Changing the ‘childText’ value in the editor seems to work fine.

  3. However, if i save the scene and load the scene again, the ‘childText’ value will remain empty.

I made a similar test with the javascript version, and it worked.
I do not understand why this is happening.

1 Like