Trace By Object Type against WorldStatic

So I want to be able to send an object to the ground with an offset.
this will be called from specific blueprints on BeginPlay() but if these objects are moved around like in C++ this should be called as well (like moving a pooled object).

my testing setup is this (the numbers are the Z height of the origin which is at their bottom center):

when I do this in blueprints directly as:

it works they are sent to .5 off the ground (even considering floating point tolerances), but where I will need this to be callable from C++ I tried to re-write it as a UFUNCTION(BlueprintCallable) with:

void AInteractableBase::SendToGround(const FVector initTarget, double ZOffset)
{
	FHitResult hitResult;

	FVector EndPoint = initTarget - FVector(0.0, 0.0, -1000.0);
	FCollisionObjectQueryParams ObjParams;
	ObjParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldStatic);

	if ( GetWorld()->LineTraceSingleByObjectType(hitResult, initTarget, EndPoint, ObjParams) )
//	if ( GetWorld()->LineTraceSingleByChannel(hitResult, initTarget, EndPoint, ECC_WorldStatic) )
//	if ( GetWorld()->LineTraceSingleByProfile(hitResult, initTarget, EndPoint, FName( TEXT("WorldStatic"))) )
	{
		EndPoint = (hitResult.Location + FVector(0.0, 0.0, ZOffset));
		UE_LOG(LogTemp, Warning, TEXT("point hit"));
	}
	else
	{
		EndPoint = initTarget;
		UE_LOG(LogTemp, Warning, TEXT("no hit"));
	}
	UE_LOG(LogTemp, Warning, TEXT("moving too %s"), *EndPoint.ToString());
	SetActorLocation(EndPoint);
}

in all 3 of these attempts I get the “no hit” response. it isn’t even hitting itself, so that isn’t a problem.

NOTE: I am testing against WorldStatic because these things might spawn above other objects and the ground, or even inside other objects (overlapping is allowed for these objects)

interesting, I am able to duplicate this behavior, but don’t know how to specifically solve why it works in blueprints, but not C++.

one possible work-around is to maybe make this a UFUNCTION(BlueprintImplementableEvent) and do it in blueprints, but then you might need to put this in either the lowest level of Blueprint Inheritance (the one that first inherits from the C++), and/or every lowest level of blueprint inheritance that will need this.

I would agree with it being an “issue” where C++ is supposed to be able to do anything Blueprints can (we might just need to include a specific Kismet header, but the Traces are reachable from CoreMinimal)

1 Like

I ended up making it UFUNCTION(BlueprintImplementableEvent, BlueprintCallable) and giving it a return type of bool (to make it a blueprint function, and so I didn’t need to setup a dispatcher to call an event on the same blueprint, even though I had to still give it BlueprintCallable so that I could call a blueprint function in the same blueprint :person_facepalming:)

this works, but I would still much prefer being able to do the same line-trace and just call that from the blueprint into C++ to save having to dive into blueprints for something it should not be directly needed for.

1 Like