Code mistake?

In method

FCollisionShape UPrimitiveComponent::GetCollisionShape(float Inflation) const
	// This is intended to be overridden by shape classes, so this is a simple, large bounding shape.
	FVector Extent = Bounds.BoxExtent + Inflation;
	if (Inflation < 0.f)
		// Don't shrink below zero size.
		Extent = Extent.ComponentMax(FVector::ZeroVector);

	return FCollisionShape::MakeBox(Bounds.BoxExtent + Inflation);

the Extent variable is computed, but not used. I suppose the intent was to have last line:

return FCollisionShape::MakeBox(Extent + Inflation);

And Infaltion is already added to BaseExtent so it should not be added in MakeBox call.

And the line
if (Inflation < 0.f)
makes no sense for me. I think Extent should be checked instead.

Hi Sashka,

Thank you for pointing this out to us. After looking over the code here, I believe you are correct in this being a mistake. I suspect that the return line is intended to be: return FCollisionShape::MakeBox(Extent);

I have entered a ticket to have this investigated further (UE-22436).


Hi Yata,

From what I can tell, the code here is operating on the assumption that Bounds.BoxExtent contains an FVector value greater than zero. I’m not sure if this is verified anywhere else in the code. Since the float value being passed in can be negative, the if statement checks to make sure Extent does not contain a negative FVector, and sets it equal to ZeroVector if it is. This should only be possible if the value passed in is negative.

It may make sense to check Extent against ZeroVector in this case, but only if we do not make sure BoxExtent never contains a negative value. I am trying to find out if we do check this somewhere else.


Yes, you are right Tim, I missed that Inflation is a float value, so there is some optimization in terms of count of comparisons. In general way this code should be equal to simple line

FVector Extent = (Bounds.BoxExtent + Inflation).ComponentMax(FVector::ZeroVector);