Quantcast
Channel: Cocos中文社区 - 最新主题
Viewing all articles
Browse latest Browse all 91167

3.0预制件实例化addChild异常SetActive of null

$
0
0
  • Creator 版本: 3.0

  • 重现方式:
    新项目
    添加2D,Sprite,名A,附加2D物理组件Rigidbody和BoxCollider
    复制A为B,放在A下面,改Rigidbody的Type为Kinematic
    复制A为C,转为预制件,从场景管理器删除C
    创建脚本:
    @property(Prefab)
    prefab:Prefab=null!;
    start () {
    var cld=this.node.getComponent(Collider2D)
    console.log(“start”, cld)
    cld?.on(Contact2DType.BEGIN_CONTACT, _=>{
    const obj=instantiate(this.prefab) as Node
    obj.parent=this.node
    })
    }
    脚本拖给A
    打开A的EnableContactListener
    预制件C托给脚本的prefab属性
    运行

  • 首个报错:
    rigid-body.ts:197 Uncaught TypeError: Cannot read property ‘SetActive’ of null
    at b2RigidBody2D.setActive (rigid-body.ts:197)
    at b2RigidBody2D.onEnable (rigid-body.ts:53)
    at RigidBody2D.onEnable (rigid-body-2d.ts:505)
    at OneOffInvoker.invokeOnEnable [as _invoke] (component-scheduler.ts:318)
    at OneOffInvoker.invoke (component-scheduler.ts:148)
    at NodeActivator.activateNode (node-activator.ts:191)
    at Node._onHierarchyChangedBase (base-node.ts:1320)
    at Node._onHierarchyChanged (base-node.ts:1261)
    at Node.setParent (base-node.ts:454)
    at Node.setParent (node.ts:370)

  • 编辑器操作系统: win10

  • 重现概率:必现

  • 其他: 用addChild替换parent=,也是一样的结果

1 个帖 - 1 位参与者

阅读整个主题


Viewing all articles
Browse latest Browse all 91167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>