Fairly new to UE5 and C++, I’d like to be able to do this from C++ so any input would be greatly appreciated
.
What I’d like to do is spawn the spell projectile actor at the trace start point and have it arc towards the trace end point. I thought to do this in the actors beginplay() and use a timeline but not entirely sure how to pass these FVector values of the trace start and trace end to the actor in the blueprint or C++ code (if you can even use timeline in C++).
Basically, what I have so far is, i drag a UI element to a point on screen and drop and then calculate a line trace in the world coords based on the start and end position of that UI elements screen position when i end the drag.
I know this sounds quite abstract and i probably did a horrible job of explaining what i want to achieve so if you are willing to provide any assistance i’ll definitely expand if needed!!
`bool UHUDLayout::NativeOnDrop(const FGeometry& InGeometry, const FDragDropEvent& InDragDropEvent, UDragDropOperation* InOperation)
{
Super::NativeOnDrop(InGeometry, InDragDropEvent, InOperation);
UDragWidget* DragWidgetResult = Cast<UDragWidget>(InOperation);
if (!IsValid(DragWidgetResult))
{
UE_LOG(LogTemp, Warning, TEXT("Cast returned null."))
return false;
}
// Calculate how far it was dragged from start to end
const FVector2D DragWindowOffset = InDragDropEvent.GetScreenSpacePosition();
const FVector2D DragWindowOffsetResult = DragWindowOffset - DragWidgetResult->DragOffset;
// Start of drag
FVector WorldPositionWidget;
FVector WorldDirectionWidget;
// End of drag
FVector WorldPositionWindow;
FVector WorldDirectionWindow;
// Deprojection of widget start of drag position in world coords
UGameplayStatics::DeprojectScreenToWorld(UGameplayStatics::GetPlayerController(this, 0), DragWidgetResult->DragOffset, WorldPositionWidget, WorldDirectionWidget);
// Deprojection of widget end of drag position in world coords
UGameplayStatics::DeprojectScreenToWorld(UGameplayStatics::GetPlayerController(this, 0), DragWindowOffset, WorldPositionWindow, WorldDirectionWindow);
// line trace output values saved here
FHitResult OutHitResult;
FCollisionQueryParams LineTraceParams;
FVector Start = WorldPositionWidget;
FVector End = WorldPositionWindow + WorldDirectionWindow * DragWindowOffset.Length();
// Line trace from beginning of drag to end of drag
bool bHitSomething = GetWorld()->LineTraceSingleByChannel(OutHitResult, Start, End, ECollisionChannel::ECC_Visibility, LineTraceParams);
// Debug line drawn from trace result beginning to end
DrawDebugLine(
GetWorld(),
OutHitResult.TraceStart,
OutHitResult.TraceEnd,
FColor(255, 0, 0),
true, -1.0f, (uint8) 0U, 0.1f
);
DragWidgetResult->WidgetReference->SetVisibility(ESlateVisibility::Visible);
DragWidgetResult->WidgetReference->SetPositionInViewport(DragWindowOffsetResult, false);
return true;
};`