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');
}
}