10{
11 if (InWorld == nullptr)
12 {
13 return;
14 }
15
16 const APlayerController* PC = InWorld->GetFirstPlayerController();
17
18 if (PC == nullptr)
19 {
20 return;
21 }
22
23 APawn* Pawn = PC->GetPawn();
24
25 if (Pawn == nullptr)
26 {
27 return;
28 }
29
30 TArray<AActor*> PlayerStarts;
31 UGameplayStatics::GetAllActorsOfClass(InWorld, APlayerStart::StaticClass(), PlayerStarts);
32
33 const AActor* MatchedStart = *Algo::FindByPredicate(PlayerStarts, [this](AActor* Actor)
34 {
35 const APlayerStart* PS = Cast<APlayerStart>(Actor);
36 return PS && PS->PlayerStartTag ==
TargetTag;
37 });
38
39 if (MatchedStart == nullptr)
40 {
41 return;
42 }
43
44 const FVector Location = MatchedStart->GetActorLocation();
45 const FRotator Rotation = MatchedStart->GetActorRotation();
46
47 Pawn->SetActorLocationAndRotation(Location, Rotation, false, nullptr, ETeleportType::TeleportPhysics);
48}
FName TargetTag
Definition LPP_ByTaggedPlayerStart.h:25