# onShapeHit never gets called

**URL:** <https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847>\
**Category:** Physics Modeling (closed)\
**Created:** [December 30, 2013, 3:22pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847 "2013-12-30T15:22:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [December 30, 2013, 3:22pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/1 "2013-12-30T15:22:51Z")

</div>

Hi,

I was implementing CharacterControllers into my engine and came across an odd problem:  
My Controllers wont collide with static geometry and even though I set a callback onShapeHit never gets called. When running my sample with PVD attached it looks like all the shapes are there but even when they start to overlap onShapeHit isn’t called.  
Furthermore the character tosses dynamic actors around.  
So to me it seems the character controller behaves strictly like a dynamic kinematic actor (which it is under the hood).  
I have the eSCENE\_QUERY\_SHAPE and eSIMULATION\_SHAPE set for all shapes and use the move() method of the character controller, which i thought would call onShapeHit.

This is my code for creating the CharacterController, I couldn’t spot any differences to the sample code shipped with the PhysX sdk.

```auto
PxCapsuleControllerDesc sDesc;
    sDesc.position = PxExtendedVec3( position.GetX(), position.GetY(), position.GetZ() );
    sDesc.userData = pElement;

    sDesc.radius = radius;
    sDesc.height = height;
    sDesc.slopeLimit = slopeLimit;
    sDesc.contactOffset = 0.1f;
    sDesc.stepOffset = 0.02f;
    sDesc.callback = this;
    sDesc.behaviorCallback = this;

    sDesc.material = pMaterial;

    if (sDesc.isValid())
        (*out_Character) = m_CharacterManager->createController( *m_pPhysX, scene.m_pScene, sDesc );
    else
        ReportPhysXError( GetName( ), "CreateCapsuleCharacter", "CharacterDescription invalid", ILoggingService::Error );

    PxRigidDynamic* pActor = (*out_Character)->getActor( );
    if ( pActor )
    {
        if ( pActor->getNbShapes( ) )
        {
            PxShape* ctrlShape;
            pActor->getShapes( &ctrlShape, 1 );

            if ( ctrlShape )
            {
                ctrlShape->setFlag( PxShapeFlag::eSCENE_QUERY_SHAPE, false );
            }
        }
    }

```

This is how i call move

```auto
PxControllerFilters filter = PxControllerFilters( );

    PxU32 collisionFlags = m_pController->move( CBVECTOR3D_2_PXVEC3( direction ), 0.001f, m_dt, filter );

    if ( PxControllerFlag::eCOLLISION_DOWN == collisionFlags )
    {
        // do something
    }

```

I used PVD to inspect my scene and the sample scene. There were no differences in the actors and shapes attributes.

Is there any flag I could habe possibly disabled that breaks the functionality of move()? I can’t shake the feeling that is something really minor I am missing here.

Thanks in advance for any help

Edit: attached a PVD scene with my scene. It has a Static and a Dynamic Actor and the Character Controller.  
[CharacterCtrl.zip](https://forums.developer.nvidia.com/uploads/short-url/lfeKkg1CCsOhxWODRqALZXY2vuc.zip) (325 KB)

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 1, 2014, 2:25pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/2 "2014-01-01T14:25:56Z")

</div>

Hi,

please write which version of PhysX do you use.  
I guess PhysX 3.2.x

One other thing: I think its not recommended to inheriate your “player” class the PxSimulationEventCallback - use a new class for it.  
[If you have many “players” with different behaviour as example, its easier to modify it]

I didnt saw the PVD, but are your dynamic objects collideds with the trimesh?

Did you use a custom filtershader?  
(Is m\_dt a small value - (how fast are your player moving [gravity])

(Maybe your Trimesh face order is wrong)

Maybe the PhysXGuide or the Samples / Snipptes could help you.  
Especially the Sample: Bridges / Character.  
Please look inside it!

Do you get any Debug messages?

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 1, 2014, 4:08pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/3 "2014-01-01T16:08:45Z")

</div>

Yes its 3.2.x.  
Yes I use a custom filter and it gets called when a dynamic actor overlaps with my controller but not when a static overlaps with it.

All other dynamics interact correctly with the heightfield. They also get tossed around by the character controller.

I checked the sampled but I still don’t see what I am missing.

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 1, 2014, 5:10pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/4 "2014-01-01T17:10:47Z")

</div>

Hi,

please post your custom filter.  
There is a sample which shows a PxController walking on a heightfield - I guess  
your filter is wrong.

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 2, 2014, 12:37pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/5 "2014-01-02T12:37:02Z")

</div>

Hi,

I don’t think the filter is the problem. I looked into the Northpole sample, which has a character walking on a heightfield and colliding with a static triangle mesh. The filter in this sample is not called when the character collides with statics. Only collisions with dynamics trigger the filter. Statics trigger onShapeHit (although not in my case).

Anyways this is my filter

```auto
static PxFilterFlags testCCDFilterShader(
    PxFilterObjectAttributes attributes0,
    PxFilterData filterData0,
    PxFilterObjectAttributes attributes1,
    PxFilterData filterData1,
    PxPairFlags& pairFlags,
    const void* constantBlock,
    PxU32 constantBlockSize )
{
    if ( filterData0.word3 & filterData1.word3 )
    {
        pairFlags |= PxPairFlag::eRESOLVE_CONTACTS;
        pairFlags |= PxPairFlag::eSWEPT_INTEGRATION_LINEAR;
    }

    return PxFilterFlag::eDEFAULT;
}

```

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 2, 2014, 1:05pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/6 "2014-01-02T13:05:04Z")

</div>

Hi,

Sorry I dont use PhysX 3.2x anymore, I´m using PhysX 3.3.  
If I remember corretly, you have to set the ControllerCallback from the controllerManager pointer.

This changed in PhysX 3.3 - to a better system, each controller have to set a individual callback.  
This is what im doing in 3.3:

mControllerDesc.reportCallback = reinterpret\_cast\<PxUserControllerHitReport\*(…);

Your filtershader seems ok.

Maybe you have to set some values in the sceneDesc while creating Physics.

Why dont you change your project to PhysX 3.3 ? (release version of course)

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 2, 2014, 1:57pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/7 "2014-01-02T13:57:15Z")

</div>

Hi,

okay updating to 3.3 seems like a good idea :)  
I did build a debug version of the PhysX3CharacterKinematicCHECKED\_x86.dll and when going through the whole move method it seems like my shapes don’t get enumerated by the scenequery.  
I saw that the scene query flag for statics is set and all my shapes have eSCENE\_QUERY\_SHAPE set to true.

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 2, 2014, 3:17pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/8 "2014-01-02T15:17:22Z")

</div>

Hi,

PhysX 3.3 fixed many bugs from 3.2.x and its faster than the older versions.

I just wondering why you wrote:

ctrlShape-\>setFlag( PxShapeFlag::eSCENE\_QUERY\_SHAPE, false );

- It disables the Overlap / Raycast test for this shape.

Maybe you did something inside the creation of the PxHeighfield wrong - maybe you could post the creation of it.

Thats a little bit strange - does the samples work corretly for you?  
Do you mix a /MTd build with /MDd build dont you?

Is there any warnings or other messages?

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 2, 2014, 3:56pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/9 "2014-01-02T15:56:24Z")

</div>

The sample works fine.

```auto
ctrlShape->setFlag( PxShapeFlag::eSCENE_QUERY_SHAPE, false );

```

Disdable the Character shape is recommended in the doumantation, but even turning it on again doesn’t solve my problem.

I’ll look into scene queries maybe I can find the root of the problem there.

I moved from a heightfield to a static box actor just to test it. Same result.

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 2, 2014, 7:01pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/10 "2014-01-02T19:01:04Z")

</div>

Hi,

maybe you forgot to create the PxScene with the flags: ( If needed )

sceneDesc.flags |= PxSceneFlag::eENABLE\_KINEMATIC\_STATIC\_PAIRS | PxSceneFlag::eENABLE\_KINEMATIC\_PAIRS;

[PxController is kinematic, your static geometry is, of course static]

I dont need these flags, it works perfectly.  
Or maybe your callback have a typo or something else was wrong written.

Did you already changed to PhysX 3.3?

Its better to post some code snippets where the problem could be - and to answer all of my hints :)

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 2, 2014, 7:18pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/11 "2014-01-02T19:18:24Z")

</div>

Okay now I am sure what the problem is. For some reason my shapes won’t show up in scene queries.  
Is there any other setting besides eSCENE\_QUERY\_SHAPE (which is turned on) the needs to be enabled for scene queries to work?

---

<div class="post-metadata">

**Author:** ![ScreenOfDeath](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ScreenOfDeath](https://forums.developer.nvidia.com/u/ScreenOfDeath)\
**Post date:** [January 3, 2014, 10:48am UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/12 "2014-01-03T10:48:53Z")

</div>

Hi,

again, it would be much easier if you answer all my questions / show some code.

And please try what I wrote.

---

<div class="post-metadata">

**Author:** ![DelBero](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@DelBero](https://forums.developer.nvidia.com/u/DelBero)\
**Post date:** [January 3, 2014, 2:57pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/13 "2014-01-03T14:57:46Z")

</div>

Hi,

finally I found the root of my problem.  
Its the client ID. I created my scene with a client ID and set all my actors to use this ID.  
But it looks like this breaks scene queries, I guess its a bug?  
When I change my ID back to PX\_DEFAULT\_CLIENT everything works fine.

---

<div class="post-metadata">

**Author:** ![icaro56](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@icaro56](https://forums.developer.nvidia.com/u/icaro56)\
**Post date:** [March 13, 2014, 2:41pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/14 "2014-03-13T14:41:54Z")

</div>

I am with similar problem.

When I use this code there is colision with terrain:

```auto
unsigned auxflags = controller->move(Convert::toPx(motion), minMoveDistance, dt, physx::PxControllerFilters(0));

```

When I use this code there is not collision with terrain:

```auto
const physx::PxControllerFilters filters(mFilterData);
unsigned auxflags = controller->move(Convert::toPx(motion), minMoveDistance, dt, filters);

```

mFilterData receives the same filter data from shape’s controller. But in this case, I don’t use filter callback for test and anyway there is not collision.

My filterData is:

```auto
word0 = groupReportCollision;
word1 = groupsMaskReportCollision; //with which groups will report collision
word2 = layerGroup

```

---

<div class="post-metadata">

**Author:** ![icaro56](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@icaro56](https://forums.developer.nvidia.com/u/icaro56)\
**Post date:** [March 13, 2014, 4:49pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/15 "2014-03-13T16:49:02Z")

</div>

a found the same bug in topic: [[Bug?] filterData for character controller - Physics Modeling (closed) - NVIDIA Developer Forums](https://devtalk.nvidia.com/default/topic/609618/?comment=3947185)

---

<div class="post-metadata">

**Author:** ![icaro56](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@icaro56](https://forums.developer.nvidia.com/u/icaro56)\
**Post date:** [March 13, 2014, 5:16pm UTC](https://forums.developer.nvidia.com/t/onshapehit-never-gets-called/31847/16 "2014-03-13T17:16:00Z")

</div>

My problem is that I only was using the function:

```auto
pxShape->setSimulationFilterData(filterData);

```

Now, I set to all other shapes the QueryFilterData:

```auto
pxShape->setSimulationFilterData(filterData);
pxShape->setQueryFilterData(filterData);

```
