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)