Download

How do I get my ContactModifyCallback to work?

I have a class MyContactModifyCallback, which inherits PxContactModifyCallback, I don’t know how to make it work in the ue4 project.

class MyContactModifyCallback : public PxContactModifyCallback
{
public:
	virtual void onContactModify(PxContactModifyPair* const pairs, PxU32 count)
	{
		UE_LOG(LogTemp, Error, TEXT("bbbbbbbbbbb"))
		for (PxU32 i = 0; i < count; i++)
		{
			auto p = pairs[i];
			for (PxU32 j = 0; j < p.contacts.size(); j++)
				p.contacts.ignore(j);
		}
	}
};

I tried to set it like this in GameMode.InitGame, but it didn’t work.

void AtestGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
	AGameModeBase::InitGame(MapName, Options, ErrorMessage);

	auto s = this->GetWorld()->GetPhysicsScene(); 
	printf("%p", s);
	s->GetPxScene()->setContactModifyCallback(new MyContactModifyCallback());
}

Anybody help?

Im not too familiar with PhysX, but docs say:

You can enable the use of this contact modification callback by raising the flag [PxPairFlag::eMODIFY_CONTACTS] in the filter shader/callback (see
PxSimulationFilterShader] for a pair of rigid body objects.

PhysX doc

Thanks, But I still don’t know how do I get it to work in UE4