instantiate 加载 prefab 之后，调用prefab 组件方法时候有时候找不到

myh0705
Tue, 12 Mar 2019 02:32:06 +0000

比如；在游戏页面页面 加载了用户头像prefab
addPlayerNode(data){
let playerNode = cc.instantiate(this.playerNodePrefab);
playerNode.parent = this.playerPosNode;

    let index = this.playerPosList[data.seatIndex];
    playerNode.getComponent('playerNode').initWithData(data,index);

},

有时候模拟器就会报错
Simulator: ERROR: Uncaught TypeError: Cannot read property ‘initWithData’ of null, location: assets/scripts/gameScene/gameScene.js:0:0
STACK:
[0]addPlayerNode@assets/scripts/gameScene/gameScene.js:196
[1]anonymous@assets/scripts/gameScene/gameScene.js:105
[

阅读整个主题