LoginSignup
1
1

More than 5 years have passed since last update.

UE4のVR Preview開始時に高さが合わないのを何とかしたかった

Last updated at Posted at 2018-01-12

はじめに

UE4でVR Previewを見るときにPlayボタンを押してからOculusを被っていたんですが、センサーの範囲外だとカメラが床の高さになってしまい、やり直しが面倒なので四苦八苦した記録です。

VR Previewを遅延させてみる

VR Previewを実行した時にOculusがセンサーの範囲に入っていればいいので、VR Previewの前に遅延を入れてみました。
それで必要なことは次の3つです。

  • 実行の契機となるもの(ボタンとか)
  • タイマー
  • BluepirntもしくはC++からVR Previewの機能を実行する方法

1つ目はエディタ拡張にするには大袈裟なのでalweiさんのUE4 Blutilityによるお手軽なエディター拡張で解説されている方法のうち、GlobalEditorUtilityBaseを継承したBlutilityアセットをダブルクリックして呼び出す方法を使います。

2つ目はBlueprintのSet Timer by Eventノードを使います。

3つ目は試行錯誤した結果、VR Previewの機能そのものを直接実行できなかったので、PlayボタンのキーボードショートカットのAlt+Pをツールバーに送る事で実現できました。
これは関数ライブラリーとしてC++クラスを追加して次のコードを書きます。

MyBlueprintFunctionLibrary.h
#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"

UCLASS()
class MYPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

    UFUNCTION(BlueprintCallable, Category="MyBPLibrary")
    static void PlayInEditor();
};
MyBlueprintFunctionLibrary.cpp
#include "MyBlueprintFunctionLibrary.h"
#include "Kismet2/DebuggerCommands.h"

void UMyBlueprintFunctionLibrary::PlayInEditor()
{
    FPlayWorldCommands::GlobalPlayWorldActions->ProcessCommandBindings(EKeys::P, FModifierKeysState(false, false, false, false, true, true, false, false, false), false);
}

依存モジュールがあるのでPublicDependencyModuleNames"Slate", "SlateCore", "UnrealEd"を追加します。

MyProjectBuild.cs
using UnrealBuildTool;

public class MyProject : ModuleRules
{
    public MyProject(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

        PrivateDependencyModuleNames.AddRange(new string[] { });

        if (Target.bBuildEditor == true)
        {
            PublicDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore", "UnrealEd" });
        }

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    }
}

適当なフォルダにBlutilityを作って以下のノードを組みます。
そしてこのアセットを呼び出すと3秒後にVR Previewが始まります(厳密には最後に実行したプレイモード)
やったね!

image.png

もっと簡単な方法

レベルブループリントに以下のノードを組んでおけばOculus Touchの左コントローラーのメニューボタンを押したときに位置トラッキングをリセットできるのでした。ちゃんちゃん

image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1