Why is 'contacts.ignore' not take effect?

Hi, everyone!

I testing my custom collision filter through FContactModifyCallback. In my testing, The character added itself to the bomb’s filter list on the bomb be spawning. My contact modifies callback checking the filter list and ignore the contact if the character in the bomb’s filter list. This worked if the bomb hasn’t dropped on the ground. On the bomb dropped on the ground, The character’s location has been adjusting forced, And the character will not be able to walk through the bomb. How fix it? Thanks!

void onContactModify(PxContactModifyPair* const pairs, PxU32 count)
	{
		for (PxU32 i = 0; i < count; i++)
		{
			PxContactModifyPair& pair = pairs[i];
			for (PxU32 j = 0; j < pair.contacts.size(); j++)
			{
				const FBodyInstance* bodyInst1 = FPhysxUserData::Get<FBodyInstance>(pair.actor[0]->userData);
				if (!bodyInst1)
				{
					UE_LOG(LogTemp, Error, TEXT("!bodyInst1"))
					continue;
				}
				AActor* actor1 = bodyInst1->OwnerComponent->GetOwner();

				const FBodyInstance* bodyInst2 = FPhysxUserData::Get<FBodyInstance>(pair.actor[1]->userData);
				if (!bodyInst2)
				{
					UE_LOG(LogTemp, Error, TEXT("!bodyInst2"))
					continue;
				}
				AActor* actor2 = bodyInst2->OwnerComponent->GetOwner();

				assert(actor1 && actor2);

				ABombBase* bomb = nullptr;
				bomb = dynamic_cast<ABombBase*>(actor1);
				if (bomb != nullptr)
				{
					assert(dynamic_cast<Atest2Character*>(actor2));
					if (bomb->isCollisionIgnoreActor(actor2))
					{
						UE_LOG(LogTemp, Error, TEXT("isCollisionIgnoreActor1"))
						pair.contacts.ignore(j);
					}
				}
				else
				{
					bomb = dynamic_cast<ABombBase*>(actor2);
					if (bomb != nullptr)
					{
						assert(dynamic_cast<Atest2Character*>(actor1));
						if (bomb->isCollisionIgnoreActor(actor1))
						{
							UE_LOG(LogTemp, Error, TEXT("isCollisionIgnoreActor2"))
							pair.contacts.ignore(j);
						}
					}
				}
			}
		}
	}

Unsure what you’re trying to do Contact Modifiers are an advanced feature and only suitable for objects simulating Physics, they can’t be used with characters since they are kinematic objects and do not generate contacts.

You also should never use dynamic_cast in Unreal - use Cast<>. dynamic_cast doesn’t work anyway, it’s redefined to Cast<>.

Thanks, How do I customize advanced collision filtering for character ? In my project, I need to filter the collision if bombs created by the characters and clear the filter when the characters overlap end.

You can use MoveIgnoreActors (on both the bomb and character) to have them ignore each other, that’s common for projectiles.

You could then perform a collision query each tick until the bomb and character are no longer overlapping, then disable the MoveIgnoreActors behaviour. Most of the time a timer or something is sufficient though.

1 Like

Thanks!

For anyone running into this in the future, here is a link to @tancen 's own great answer! :slight_smile: