hi, I am trying to switch to VR and Non VR at runtime, but it is not working, Please help
void AMyPlayerController::ChangeApplicationMode(EApplicationMode::Type NewMode)
{
APawn* PrvPawn = m_pPawn;
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = NULL;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
APawn* NewPawn = nullptr;
if (NewMode == EApplicationMode::VirtualReality)
{
if (UHeadMountedDisplayFunctionLibrary::EnableHMD(true))
{
NewPawn = GetWorld()->SpawnActor<APawn>(VrPawnBlueprint, SpawnParams);
}
}
else
{
if (UHeadMountedDisplayFunctionLibrary::EnableHMD(false))
{
NewPawn = GetWorld()->SpawnActor<APawn>(DesktopPawnBlueprint, SpawnParams);
}
}
if (NewPawn != nullptr)
{
UnPossess();
Possess(NewPawn);
PrvPawn->Destroy();
}
}