Need help with configuring scene overlap query

I’m trying to use Physx to perform an overlap query on my scene, but am having trouble based off of the documentation. I am following the information here: Scene Queries — NVIDIA PhysX SDK 4.1 Documentation

Based off of the example in the SDK Guide, I created my own callback class, inheriting from PxOverlapCallback:

		struct OverlapCallback : physx::PxOverlapCallback {
			OverlapCallback(userData* userData)  : physx::PxOverlapCallback(NULL, 0)  {
				mUserData = userData;

			physx::PxAgain processTouches(const physx::PxOverlapHit* buffer, physx::PxU32 nbHits) {
				std::cout << "Number of overlap hits: " << nbHits << std::endl;
				return true;

			void finalizeQuery() {
				std::cout << "Finalizing query" << std::endl;

			userData* mUserData;

However, if I utilize this callback function, I get an error from Physx:

physx\src\53e20a06fa-b4a222d4bd.clean\physx\source\physx\src\NpSceneQueries.cpp (709) : invalid parameter : PxScene::overlap() and PxBatchQuery::overlap() calls without eANY_HIT flag require a touch hit buffer for return results.

But isn’t the point of using the callback that I don’t need a buffer? The default flag for overlap queries should be eNO_HIT, so I’m not sure why I’m getting this error.

thanks in advance for any pointers or help you can provide!

At the moment, you will have to provide the buffers as there is code that requires them to be present inside the queries themselves. We are aware of this issue and a major overhaul of the SQ system is being worked on as part of PhysX 5.

Ah, got it – so the callback system doesn’t work in Physx 4 and I need to use the buffers?

I tried using the buffers exactly as in the SDK example:

PxOverlapBuffer hit;            // [out] Overlap results
PxGeometry overlapShape = ...;  // [in] shape to test for overlaps
PxTransform shapePose = ...;    // [in] initial shape pose (at distance=0)

PxOverlapBuffer hit;
bool status = scene->overlap(overlapShape, shapePose, hit);

But I’m still getting the same error:

invalid parameter : PxScene::overlap() and PxBatchQuery::overlap() calls without eANY_HIT flag require a touch hit buffer for return results.

Do I need to enable any other hit flags or set up the buffer in a different way?

The API can be confusing. There are helpers in the Extensions library that might make it easier to use. Specifically in your case, look up PxSceneQueryExt::overlapAny and PxSceneQueryExt::overlapMultiple for how to use the overlap call with or without a touch buffer.

Are there any snippets or examples to show how to use it? I couldn’t find any in the repository.

The SampleNorthPole sample uses a boolean overlap query to check whether it can resize the character controller, for example: PhysX/SampleNorthPoleCCT.cpp at 4.1 · NVIDIAGameWorks/PhysX · GitHub

FWIW some years ago I had a number of overlap test scenes in PEEL (a personal tool). The latest code there was for PhysX 3 but the API hasn’t changed much so it could still be useful. There were a number of scenes for overlap-any / overlap-multiple / etc / etc, many different variations. Relevant code would be around there: PEEL/PINT_CommonPhysX3.cpp at master · Pierre-Terdiman/PEEL · GitHub

Thanks so much Pierre! I’ll take a look.

Just wanted to follow up – I got it working using the extension calls; thanks so much!