Line trace bug

I’m using line trace to do some calculations. It’s used from C++ during the editor time. Whole scene is loaded using custom factory (i.e. meshes are created via custom classes not via fbx importer).

So, when I import everything first time and do line traces everything works fine. I can repeat calculations, unload and load level again and still works fine.

BUT, if I close UE and run it again, then repeat exactly the same line traces, then it’s not working. All traces fail.

The code I’m using

TArray<AActor*> Actors;
bool bResult = UKismetSystemLibrary::LineTraceSingle_DEPRECATED(ActorToIgnore, Start, End, ECC_Visibility, true, Actors, EDrawDebugTrace::ForDuration, HitOut, true, FLinearColor::Blue, FLinearColor::White, 60.0f);

You see that collision is OK. NOTHING is changed betwen closing and running UE editor. Looks like a bug?

Hey -

Based on the code provided, you’re using the depreciated version of the LineTraceSingle() function. Try using UKismetSystemLibrary::LineTraceSingle_NEW(); instead to see if that helps.

Cheers

bool UKismetSystemLibrary::LineTraceSingle_NEW(UObject* WorldContextObject, const FVector Start, const FVector End, ETraceTypeQuery TraceChannel, bool bTraceComplex, const TArray<AActor*>& ActorsToIgnore, EDrawDebugTrace::Type DrawDebugType, FHitResult& OutHit, bool bIgnoreSelf, FLinearColor TraceColor, FLinearColor TraceHitColor, float DrawTime)
{
return LineTraceSingle_DEPRECATED(WorldContextObject, Start, End, UEngineTypes::ConvertToCollisionChannel(TraceChannel), bTraceComplex, ActorsToIgnore, DrawDebugType, OutHit, bIgnoreSelf, TraceColor, TraceHitColor, DrawTime);
}
That’s how old and new functions are related, they’re basically the same. And I totally don’t understand what to pass as ETraceTypeQuery TraceChannel, and there’s zero info about this.

enum ETraceTypeQuery
{
	TraceTypeQuery1 UMETA(Hidden), 
	TraceTypeQuery2 UMETA(Hidden), 
	TraceTypeQuery3 UMETA(Hidden), 
	TraceTypeQuery4 UMETA(Hidden), 
    ............
	TraceTypeQuery27 UMETA(Hidden), 
	TraceTypeQuery28 UMETA(Hidden), 
	TraceTypeQuery29 UMETA(Hidden), 
	TraceTypeQuery30 UMETA(Hidden), 
	TraceTypeQuery31 UMETA(Hidden), 
	TraceTypeQuery32 UMETA(Hidden),

	TraceTypeQuery_MAX	UMETA(Hidden)
};

And I’ve tried NEW version with ETraceTypeQuery::TraceTypeQuery1 (which seems correspond to ECC_Visibility) which gives me absolutely same results.

OK, during my calculations I was rebuilding static mesh components. So to make everything work I had to reinit BodySetup of the static mesh (collision part of it). Case closed.