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

比如;在游戏页面页面 加载了用户头像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
[

报错上面还有个警告[WARN]: Script attached to ‘playerNode’ is missing or invalid.

@jare 这是什么原因有时候不加载啊?麻烦看一下呗

警告已经提示你了啊,脚本附件的节点对象丢了或者无效,你可以打开预制体再检查一下

我这个不是每次都丢失,是有时候发生,有时候没问题,这个什么原因啊

生命周期问题

哦哦,谢谢回答,那这应该怎么修改啊?