Overlap event not firing when overlapping with two objects

I have a very basic scene setup which in essence is a Pong scene with two paddles, a ball, and a top and bottom wall. I’ve been trying to fix this bug for a while now where sometimes if the ball hits the paddle and it’s extremely close to a wall, it will just go through it instead of firing the overlap event for the wall collision.

Before there was just one collision component on the paddle and the walls which would block the paddle from going through the wall and the same collision component on the wall would also stop the ball from going through it.

Now I’ve changed it so that the paddle and the walls have two separate collision components, one dedicated for overlap events with the ball and the other dedicated for stopping the paddle from going through the wall. With the new setup, I’ve made the wall blocking collision component in the paddle to be a bit longer than the ball overlap collision component so that the paddle and the wall never actually come in contact with each other but this does not work either. I’m basically at a complete loss now.

All of my blueprints are also extended from code and I’m not using any movement components for moving the ball or the paddle, just used some simple coding to get the ball and paddle moving the way I want it to. If it would help, I can share the code as well, the reason I didn’t is because my codebase has grown quite large at this point so I’m not sure how much of it I should share.

just wanted to bump this since no reply yet

You can share your .cpp where your overlap methods are implemented ?

So basically I have a function in the ball class which basically flips the Z velocity when it hits a wall. Before I used this function within the balls

OnComponentBeginOverlap event.
void AmainBall::wallCollisionProcedure()
{
functioningVelocity.Z = functioningVelocity.Z * -1.0;

	addPaddlePoints(previousPaddleRightSide, wallHitPoints * pointsSpeedMultiplier);

	if (isPlayerCentricMode)
	{
		if (previousPaddleControllable)
		{
			spawnFloatingText(wallHitPoints * pointsSpeedMultiplier);
		}
	}
	else if (!isPlayerCentricMode)
	{
		spawnFloatingText(wallHitPoints * pointsSpeedMultiplier);
	}
}

However, now I make this function public and when the ball collides with a wall, the wall calls this function in the ball.

void AwallClass::wallBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
AmainBall* collBallRef;

if (OtherActor->IsA(AmainBall::StaticClass()))
{
	collBallRef = Cast<AmainBall>(OtherActor);

	collBallRef->wallCollisionProcedure();
}

}

Like I mentioned before, I’ve just created some simple code that iterates the ball location every tick event based on the functioningVelocity vector

Hello Alieninsane,

When the ball overlaps with the paddle/wall when they’re close and ends up going through both of them, is it possible that wallCollisionProcedure is being called twice, resulting in the velocity being set back to its initial value? You should be able to tell via the floating text if both are being called at the same time, at least it seems that way.

Hmm that’s might actually be the case because I see whenever that happens I see multiple floating texts spawn. However, looking at the code in the wallClass, it should only invoke the wallCollisionProcedure from within the ball if the object that has overlapped with it is actually a mainBall class.
The only thing I see most likely to be happening is basically the ball overlapping with the paddle and the wall at the same time. In this scenario perhaps the wall invokes the wallCollisionProcedure in the ball first. Only after that the overlap procedure from within the ball which actually affects it’s Z velocity when it hits a paddle kicks in and possibly shift the Z velocity in the direction where it came from which would be through the wall.
Either way at this point after trying so many different things, I’m a bit lost.

Alright so I went back and made it so that the wallCollisionProcedure will again be handled within the mainBall’s overlap procedure and this is how it used to be originally. The following is the code for the mainBall’s overlap procedure:

void AmainBall::ballBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp,
	int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{

	if (OtherActor->IsA(ApaddleClass::StaticClass()))
	{
		collPaddleRef = Cast<ApaddleClass>(OtherActor);
		functioningVelocity.X = functioningVelocity.X * -1.0;
		previousPaddleControllable = collPaddleRef->isPlayerControlled;
		if (collPaddleRef->isMoving)
		{
			FVector tempZCalcVector;
			tempZCalcVector = collPaddleRef->directionVector * (collPaddleRef->toDistance *
				collPaddleRef->currDeltaSeconds * zVelOffset);
			functioningVelocity.Z = tempZCalcVector.Z;
		}
		else
		{
			functioningVelocity.Z = FMath::FRandRange((collPaddleRef->paddleSpeed * -1.f),
				collPaddleRef->paddleSpeed);
		}

		previousPaddleRightSide = collPaddleRef->isRightSide;

		addPaddlePoints(previousPaddleRightSide, paddleHitPoints * pointsSpeedMultiplier);

		if (isPlayerCentricMode)
		{
			if (previousPaddleControllable)
			{
				spawnFloatingText(paddleHitPoints * pointsSpeedMultiplier);
			}
		}
		else if (!isPlayerCentricMode)
		{
			spawnFloatingText(paddleHitPoints * pointsSpeedMultiplier);
		}
		

	}

	if (OtherActor->IsA(AwallClass::StaticClass()))
	{
		wallCollisionProcedure();
	}
	
}

The occurrences of the ball going through the wall at least seems to be much rarer now and I’m speaking from a small sample size of 4-5 pong matches. However, the problem is still there and now I’m thinking that perhaps it causes some problems if the ball is overlapping with more than one object at the same time.

Whether the logic is on the stationary objects or the ball itself, if both objects are overlapped at the same time, they’re not called at the same time but in a certain order.

This means that, in that span of a few milliseconds between a frame, if it overlaps with both objects, this function will be called twice. The Z velocity will be set to negative of its current value but then the function will be called a second time, setting it back to its original value. Once this happens, the ball will continue through the wall and paddle as it has already begun overlapping and will not call the “Begin” overlap event again until it has exited the overlap and then overlapped again.

You may need to set up something for the top wall to only call this function if the Z velocity is positive or something of the sort. If the overlapping is how you wish to continue handling this, it will end up needing some more conditional statements based off the velocity.

This knowledge actually helps me a lot. I think I’m going to try to set up some sort of conditional system. Right now though, I changed it so that the wall class will call any functions from within the ball when it begins overlap. Basically now the ball itself handles all changes to the Z velocity.

With this knowledge now, what I think is most likely happening, since a paddle collision does affect the ball’s Z velocity, is that when the ball is overlapping with the ball and the paddle at the same time, the wall overlap is calculated first and then immediately after the paddle overlap procedure flips the Z velocity back through random values. This I think would lead to the ball never ending an overlap with the wall if the wall and paddle are close enough.

For now I will this as answered as even if what I mentioned above is not the case then I will have to find another alternative.

Actually if you wouldn’t mind posting that commend as an answer, I will it.