A way to test if a point is inside a closed spline loop.

Sharing this here since there are barely any other posts talking about points in spines

cpp version(replace MyName with the name of your file):

bool UMyName::IsPointInsideSpline(FVector point, USplineComponent* Spline)
{
	FVector RealLocation=FVector(point.X,point.Y,Spline->GetComponentLocation().Z);
	FVector step1=Spline->FindLocationClosestToWorldLocation(RealLocation,ESplineCoordinateSpace::World)-RealLocation;
	FVector step2=Spline->FindRightVectorClosestToWorldLocation(RealLocation,ESplineCoordinateSpace::World);

	return !(FVector2D::DotProduct(FVector2D(step1).GetSafeNormal(), FVector2d(step2))>0);
}
5 Likes

thank you! I modified it a bit to make it work with rotated splines

1 Like