切换至prefab编辑器会造成场景内容丢失的问题

情况是,只要切换到prefab编辑模式,再按关闭,就会造成场景内容丢失

第一个错误讯息…

  Failed to record delete node Canvas: TypeError: Cannot read property 'undefined' of null
    at Object.recordDeleteNode  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/scene-undo.js:1:8194)
    at _Scene.NodeUtils._destroyForUndo  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/stash-scene.js:1:358)
    at Object.Utils._destroyForUndo  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/node-utils.js:1:2984)
    at d.children.forEach.e  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/stash-scene.js:1:323)
    at Array.forEach (native)
    at Object.dump  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/stash-scene.js:1:294)
    at exitScene  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/prefab-edit-mode.js:1:529)
    at cc.AssetLibrary.loadAsset  (/Applications/creator/CocosCreator.app/Contents/Resources/app.asar/editor/page/scene-utils/prefab-edit-mode.js:1:1139)
    at CCLoader.<anonymous>  (/Applications/creator/CocosCreator.app/Contents/Resources/engine/cocos2d/core/platform/CCAssetLibrary.js:110:17)

因为无法定位到是哪个property变为了undefined,
不晓得引擎能否提示下是哪个script文件造成这个问题?
或是有办法能定位到问题所在, 感谢

找到原因了,我有一个prefab是这样定义的

let prefab = cc.Class(
{
    properties:
    {
        $editbox:       { visible:false, get(){ return cc.find( '@inputs/$editbox', this.node ).getComponent( cc.EditBox ); } },

        DynamicCount:
        {
            visible:false,
            get()
            {
                let value = parseInt( this.$editbox.string );
                if( value < 0 || isNaN( value ) ) { value = 0; this.$editbox.string = '0'; }
                return value;
            },
            set(value){ if( value < 0 || isNaN(value) ) { value = 0; } this.$editbox.string=`${value}`; }
        }
    }
});

所以在切换scene至prefab编辑模式的时候,似乎会让编辑器识别出错,
所以我只要改定义成这样:


let prefab = 
{
    properties:
    {
        $editbox:       { visible:false, get(){ return cc.find( '@inputs/$editbox', this.node ).getComponent( cc.EditBox ); } },
    }
};

if( !window.CC_EDITOR )
{
    prefab.properties.DynamicCount =
    {
        visible:false,
        get()
        {
            let value = parseInt( this.$editbox.string );
            if( value < 0 || isNaN( value ) ) { value = 0; this.$editbox.string = '0'; }
            return value;
        },
        set(value){ if( value < 0 || isNaN(value) ) { value = 0; } this.$editbox.string=`${value}`; }
    };
}

let prefabClass = cc.Class( prefab )

将这个property改为非编辑器才进行定义,这样编辑器就不会因为这个属性报错了…

因为这个属性是用在执行时期的,
或许我这个使用方式是错误的

但还是希望引擎能提示一下,不要直接让场景出错

感谢反馈,这里确实是很有可能出错的一个地方。之后我们会加入一些错误处理。

1赞