Prefab作为碰撞组件的问题

我的项目中有一个Prefab,它有一个脚本,其中有一个函数是这样:
explode() {
let fx = this.spawnBoomFX()
this.node.parent.addChild(fx.node)
fx.node.setPosition(this.node.position)
fx.play()

// 擦除当前节点并生成新节点
this.node.removeFromParent()
cc.pool.putInPool(this)
this.frame.spriteFrame = this.arrow[0]

},
它在执行:
if (this.missile.y < -110) {
this.velocity = null
this.isUp = true
this.missile.getComponent(Missile).explode()//这一句
}
的时候没有问题。

但是一放到:
onCollisionEnter(other, self) {
this.explode()
},
就会提示错误:
Uncaught TypeError: Cannot read property ‘addChild’ of null
this.node.parent.addChild(fx.node)
这个节点的父节点为空
请问这个问题怎么解决?

应该是代码哪里写的有问题[quote=“1112911, post:1, topic:63149”]
let fx = this.spawnBoomFX()
[/quote]
在这里打断点看看fx是什么

这是生成一个爆炸效果动画!

那看看是不是this指向问题

https://gitee.com/demon_gh/Missile
有两个地方执行这个函数,但是只有在碰撞盒子相撞的时候会出现这个问题

你的demo能不能直接上传,你的链接要账号下载的

打断点看看是不是走了下面

怎么直接上传?

压缩直接点击上传

不行,附件太大,无法直接上传

this.parent是什么,这里好像有问题

不是这个脚本,MissileCurve.js要看这个

你这个js里面其他的都是this.node.parent,就上面那个是this.parent.node

你确定就不是MissileLine.js里面的碰撞出问题吗

这个脚本没有加载,是以前用来测试的!

会不会是哪个地方以前加载了,忘记删了,在那里打个断点看看会不会进去

下午来吧,吃饭去吧,你加我QQ

你QQ多少?

点我头像