Download

Collision modify callback unexpected behaviour

Hello.

I’ve been trying to use custom FContactModifyCallback to “carve” holes in the world.
For a test, I wrote a simple callback which should force bodies to ignore all contacts:


class FTestContactModifyCallback : public FContactModifyCallback
{
public:
    void onContactModify(PxContactModifyPair* const pairs, PxU32 count) override
    {
        for (PxU32 i = 0; i < count; i++)
        {
            pairs->contacts.ignore(i);
        }
    }
};

And a custom factory for FPhysScene_PhysX::ContactModifyCallbackFactory:


class FTestContactModifyCallbackFactory : public IContactModifyCallbackFactory
{
public:
    FContactModifyCallback* Create(FPhysScene_PhysX* PhysScene)
    {
        return new FTestContactModifyCallback();
    }

    void Destroy(FContactModifyCallback* Callback)
    {
        delete Callback;
    }
};

I assign this custom factory at StartupModule method of my game module:


...
TSharedPtr<FTestContactModifyCallbackFactory> CustomCMCFactory;

virtual void StartupModule() override
{
    CustomCMCFactory = MakeShareable(new FTestContactModifyCallbackFactory());
    FPhysScene_PhysX::ContactModifyCallbackFactory = CustomCMCFactory;
}
...

In the game, when I’m turning on contact modification for component’s body instance, body attempts to fall through the floor but gets immediatly bounced back or completly stuck in the floor until other body ‘pops’ it out. This, however, does work for spheres: they fall through floor and pass through walls without any problems.

Am I missing something for this to work properly or this can’t done this way?

Thanks in advance.

Not sure if solved, but came across this while looking for a similar collision filtering issue.

One slight change to your code and I was able to turn off all collisions between contact modified bodies, just had to change…



class FTestContactModifyCallback : public FContactModifyCallback {

public:

    void onContactModify(PxContactModifyPair* const pairs, PxU32 count) override {
        for ( PxU32 i = 0; i < count; i++ ) {
            PxContactModifyPair * pair = pairs + i;
            PxU32 n = pair->contacts.size();
            for ( PxU32 j = 0; j < n; j++ ) {
                pair->contacts.ignore(j);
            }
        }
    }

};


  • The count parameter refers to number of actor body pairs in contact.

  • Then for each actor body pair, you need to look at contacts.size() for the number of contacts.