rigid-body.ts:231
Uncaught TypeError: Cannot read properties of null (reading ‘SetActive’)
at b2RigidBody2D.setActive (rigid-body.ts:231:21)
at b2RigidBody2D.onEnable (rigid-body.ts:78:14)
at RigidBody2D.onEnable (rigid-body-2d.ts:551:24)
at OneOffInvoker.invokeOnEnable [as _invoke] (component-scheduler.ts:332:18)
at OneOffInvoker.invoke (component-scheduler.ts:162:14)
at NodeActivator.activateNode (node-activator.ts:163:31)
at Node._onHierarchyChangedBase (node.ts:1371:46)
at Node._onHierarchyChanged (node.ts:1878:14)
at Node.setParent (node.ts:509:14)
at L_Button_script.fn_Button (L_Button_script.ts:31:13)
如果没猜错,你在碰撞回调里面做了一些骚操作。
this.cur_block.activeInHierarchy == true) {
Eventdispatcher.get_taget().emit(Eventdispatcher.SCORE, -1);
就是碰撞结束后判断刚才碰撞的节点还存在就扣1分
异步执行!!
延时一帧应该就可以了,this.scheduleOnce(()=>{
Eventdispatcher.get_taget().emit(Eventdispatcher.SCORE, -1);
})
延时了0.1,没有报错了
不用延时0.1s,就按我那个方法,下一帧执行就行,这个是刚体的通病,延时0.1s其实不严谨,最好是this.scheduleOnce(()=>{}一帧就可以
谢谢 ,,,,,
你是不是在回调里生成预制体相关、或者创建销毁刚体了?是不是做跟 刚体有关的事情了?? 如果是你就在回调里记录一个状态,update()下一帧的时候 执行你的功能就行了,必须到下一帧来做操作。
