Is Engine's Error?

Which version 3xx I should use for my company’s project?

 664 
 [PreviewInEditor] Cannot read property 'enabledContactListener' of null
TypeError: Cannot read property 'enabledContactListener' of null
at PhysicsContact.emit (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:194408:21)
at PhysicsContactListener._onPreSolve [as _PreSolve] (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:194831:13)
at PhysicsContactListener.PreSolve (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:277145:18)
at b2PolygonAndCircleContact.Update (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\node_modules\@cocos\box2d\build\box2d\box2d.umd.js:11829:1)
at b2ContactManager.step [as Collide] (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\node_modules\@cocos\box2d\build\box2d\box2d.umd.js:12487:1)
at b2World.Step (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\node_modules\@cocos\box2d\build\box2d\box2d.umd.js:19595:27)
at b2PhysicsWorld.step (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:194619:23)
at PhysicsSystem2D.postUpdate (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:198074:31)
at Director.tick (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:19294:34)
at Game._updateCallback (C:\ProgramData\cocos\editors\Creator\3.8.3\resources\resources\3d\engine\bin\.cache\dev\editor\bundled\index.js:20311:22)
import { _decorator, Collider2D, Component, Contact2DType, IPhysics2DContact, Node, PhysicsSystem2D } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PlayerCollider')
export class PlayerCollider extends Component {
   start () {
       // Registering callback functions for a single collider
       let collider = this.getComponent(Collider2D);
       if (collider) {
           collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
           collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
           collider.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
           collider.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
       }

       // Registering global contact callback functions
       if (PhysicsSystem2D.instance) {
           PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
           PhysicsSystem2D.instance.on(Contact2DType.END_CONTACT, this.onEndContact, this);
           PhysicsSystem2D.instance.on(Contact2DType.PRE_SOLVE, this.onPreSolve, this);
           PhysicsSystem2D.instance.on(Contact2DType.POST_SOLVE, this.onPostSolve, this);
       }
   }
   onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
       // will be called once when two colliders begin to contact
       console.log('onBeginContact');
   }
   onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
       // will be called once when the contact between two colliders just about to end.
       console.log('onEndContact');
   }
   onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
       // will be called every time collider contact should be resolved
       console.log('onPreSolve');
   }
   onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
       // will be called every time collider contact should be resolved
       console.log('onPostSolve');
   }
}

Could you provide the demo for us to check?

I switch to 3.7.4 and the error is solved!

Ok, that is a good news, we are willing to provide developers a good experience to use Cocos, and we are want to know what is going on to the each Version of it. So we hope you could provide the demo for us to check whether the engine has got a bug on collider on the version of 3.8.3? Tks.

1 Like

HaoBeginCocosProject.zip (7.4 MB)

Here’s my demo

Tks :smile:

How can I reproduce the error?

1.you should add the rigidbody2d to the walls,
2.make sure the layer setting of two collide objects, can be collided, here is the picture:

After I have done below two steps, it can trigger the contact callbacks correctly.

Need to add rigibody in everywhere? omg, in unity, just add to player

The differences between 3.8x and 3.7x have sent to colleague. Please wait.

hello ,you can modify the emit function by refering to the picture of physics-contact-listener.ts,