RealtimeStyleTransferRuntime/Source/LyraGame/Player/LyraSpectatorPawn.cpp

49 lines
1.2 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "LyraSpectatorPawn.h"
#include "Editor.h"
#include "EngineUtils.h"
#include "LevelEditorSubsystem.h"
#include "Character/LyraCharacter.h"
#include "Character/LyraPawn.h"
// Sets default values
ALyraSpectatorPawn::ALyraSpectatorPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
void ALyraSpectatorPawn::BeginPlay()
{
Super::BeginPlay();
ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>();
LevelEditorSubsystem->EjectPilotLevelActor();
}
// Called every frame
void ALyraSpectatorPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
ULevelEditorSubsystem* LevelEditorSubsystem = GEditor->GetEditorSubsystem<ULevelEditorSubsystem>();
AActor* ActorToPilot = LevelEditorSubsystem->GetPilotLevelActor();
if (Cast<ALyraCharacter>(ActorToPilot))
return;
for (ALyraCharacter* Character : TActorRange<ALyraCharacter>(GetWorld()))
{
ActorToPilot = Character;
break;
}
if (!IsValid(ActorToPilot))
return;
LevelEditorSubsystem->PilotLevelActor(ActorToPilot);
}