Download

SweepMultiByChannel() Returning False

I’m using this function, with the start and end at the location of the character. I just want to do a sweep around the player when a button is pressed, to see if a specific object is in the area. I am returning to a bool off of this function, to see if there was a hit. It always returns false, even when the hit does hit the object (I have the debug trace drawing turned on, so I can see that it did hit the object). I have setup a custom trace channel in the editor through the project settings, and I can see it in my defaultengine.ini. I am passing that channel to the function, and the only blocking hit I have turned on on the object is that trace channel. I’m not sure what is going on here. I don’t know the tags to use to add code to a forum post, but if it will help, I will post the code.

Anybody have any ideas?

I have been trying to figure this out for a little while now, and still can’t get it. I have tried changing all the collision presets to even get it to “hit” anything, and it is still returning false. I know I am doing something wrong, I’m just not sure what:



{
	// The result of what was hit in the trace if any
	TArray<FHitResult> HitOut;
	FHitResult EmptyHit;

	ECollisionChannel CollisionChannel = ZIPLINECHANNEL;

	FCollisionQueryParams TraceParams(FName(TEXT("Platform Trace")), true, this);

	// Creating the trace tag for debug drawing of trace sphere
	const FName TraceTag("TraceTag");
	GetWorld()->DebugDrawTraceTag = TraceTag;
	TraceParams.TraceTag = TraceTag;

	TraceParams.bTraceComplex = true;

	FCollisionResponseParams ExtraParams;

	bool hit = GetWorld()->SweepMultiByChannel(
		HitOut, LineTraceBeginLoc, LineTraceEndLoc,
		FQuat::Identity, CollisionChannel,
		FCollisionShape::MakeSphere(CollisionSphereRadius),
		TraceParams, ExtraParams
		);
	
	if (hit == true)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("Hit is true"));
	}
	else if (hit == false)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("Hit is false."));
	}
	
	return EmptyHit;
}


Anybody effectively using this function?

Nevermind, figured it out. Can’t have the start location and end location in the same spot, have to offset it some. Now it works.

Sir, I just spent possibly hours not understanding why my sweep didn’t work and instead I tried reaching the same result through a different method, had my unreal crash twice, and now I find your post and can’t believe this would have solved my problems and saved me so much time. Thank you so much