{"record":{"id":"1d15404f9d8796b5","repo":"stride3d/stride","slug":"this-collidable-s-nameof-collidablereference-should-exist","errorCode":null,"errorMessage":"This Collidable's {nameof(CollidableReference)} should exist","messagePattern":"This Collidable's (.+?) should exist","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/Contacts/ContactEventsManager.cs","lineNumber":73,"sourceCode":"        {\n            foreach (var typeStore in workerStore)\n            {\n                if (typeStore.IsEmpty() == false)\n                    throw new InvalidOperationException(\"Cannot resize the manifold store, manifolds have not been flushed yet\");\n            }\n        }\n\n        _manifoldStoresPerWorker = new IPerTypeManifoldStore[newWorkerCount][];\n        for (int i = 0; i < _manifoldStoresPerWorker.Length; i++)\n            _manifoldStoresPerWorker[i] = [];\n    }\n\n    /// <summary>\n    /// Begins listening for events related to the given collidable.\n    /// </summary>\n    public void Register(CollidableComponent collidable)\n    {\n        var reference = collidable.CollidableReference ?? throw new InvalidOperationException($\"This Collidable's {nameof(CollidableReference)} should exist\");\n        if (reference.Mobility == CollidableMobility.Static)\n            _staticListenerFlags.Add(reference.RawHandleValue, _pool);\n        else\n            _bodyListenerFlags.Add(reference.RawHandleValue, _pool);\n    }\n\n    /// <summary>\n    /// Stops listening for events related to the given collidable.\n    /// </summary>\n    public void Unregister(CollidableComponent collidable)\n    {\n        var reference = collidable.CollidableReference ?? throw new InvalidOperationException($\"This Collidable's {nameof(CollidableReference)} should exist\");\n        if (reference.Mobility == CollidableMobility.Static)\n            _staticListenerFlags.Remove(reference.RawHandleValue);\n        else\n            _bodyListenerFlags.Remove(reference.RawHandleValue);\n\n        ClearCollisionsOf(collidable, reference.Packed);","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.BepuPhysics/Stride.BepuPhysics/Definitions/Contacts/ContactEventsManager.cs#L55-L91","documentation":"Register subscribes a CollidableComponent for contact events, which requires the component to already have a CollidableReference assigned by the physics simulation. A null reference means the collidable was never added to (or not yet processed by) the simulation, so there is nothing to listen for.","triggerScenarios":"Calling ContactEventsManager.Register(collidable) while collidable.CollidableReference is null — the component has not been added to the simulation's collidables, or the simulation has not yet assigned its handle.","commonSituations":"Registering a collider/physics component before the Simulation has processed it (e.g. during the same frame it was added, before ApplyDescription/initialization); the component was removed from the scene so its reference was released; wrong simulation instance ordering.","solutions":["Add/register the CollidableComponent with the simulation first, then call Register after CollidableReference is assigned.","Check collidable.CollidableReference != null before calling Register.","If the component was removed, do not re-register without re-adding it to the simulation.","Defer registration to the next physics update if it was added this frame."],"exampleFix":"// before\ncontactEvents.Register(myCollider); // CollidableReference still null\n// after\nsimulation.Collidable.Add(myCollider); // simulation assigns reference\nif (myCollider.CollidableReference != null)\n    contactEvents.Register(myCollider);","handlingStrategy":"type-guard","validationCode":"if (collidable.CollidableReference == null)\n    throw new InvalidOperationException(\"Collidable not yet added to the simulation; cannot register for contact events\");","typeGuard":"static bool CanRegister(CollidableComponent c) => c.CollidableReference is not null;","tryCatchPattern":"try { contactEvents.Register(collidable); } catch (InvalidOperationException ex) { Logger.Warning($\"Skipped contact registration: {ex.Message}\"); }","preventionTips":["Add the component to the simulation before registering it for contact events","Check CollidableReference != null before Register/Unregister","Defer registration to the next physics update if the component was added this frame","Keep a single simulation instance to avoid cross-simulation reference confusion"],"tags":["physics","collision","null-reference"],"backgroundTag":"null-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}