-
Creator 版本:2.4.7
-
目标平台: 微信开发者工具
-
重现方式:
同一个prefab,代码动态加载实例化正常。挂载在节点的脚本上则无法正常实例化,节点的active是false,无法调用onLoad 函数
挂载方式的数据:
cc.resources.load 动态加载的数据:
prefab可以正常在cocos creator中打开,且没有错误和警告。prefab_challenge_game.prefab.zip (5.8 KB)
Creator 版本:2.4.7
目标平台: 微信开发者工具
重现方式:
同一个prefab,代码动态加载实例化正常。挂载在节点的脚本上则无法正常实例化,节点的active是false,无法调用onLoad 函数
挂载方式的数据:
cc.resources.load 动态加载的数据:
prefab可以正常在cocos creator中打开,且没有错误和警告。prefab_challenge_game.prefab.zip (5.8 KB)
active =false,是不调用componet的 load的,加载后设置true,可能就正常了
挂载在节点上, data为空,isValid和loaded属性都是false,这是什么原因
重点不是active,是内部的data为null,整个prefab有问题,我设active为true也会报错
脚本贴出来
都是在SCENE的onLoad中调用的
动态加载
cc.resources.load(‘prefab/prefab_challenge_game’, cc.Prefab, (errorMessage, prefab:cc.Prefab) => {
let node: cc.Node = cc.instantiate(prefab);
this.chessboardUILayer.addChild(node);
let script = node.getComponent(mediatorScriptName);
script.setLayers(this.dialogLayer, this.tipLayer, this.chessboardLayer, this.chessboardUILayer, this.resultLayer);
script.initChessBoard();
});
挂在节点上
@property(cc.Prefab)
public gamePrefab: cc.Prefab = null;
let node: cc.Node = cc.instantiate(this.gamePrefab);
this.chessboardUILayer.addChild(node);
let script = node.getComponent(mediatorScriptName);
script.setLayers(this.dialogLayer, this.tipLayer, this.chessboardLayer, this.chessboardUILayer, this.resultLayer);
script.initChessBoard();
看到isVaild就知道了
问题是动态加载没问题,挂在脚本上加载就有问题
找到问题了,前一个场景销毁的时候把资源release了 