DEV Community

KOGA Mitsuhiro
KOGA Mitsuhiro

Posted on • Originally published at qiita.com

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

はじめに

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++クラスを追加して次のコードを書きます。

#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();
};
#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"を追加します。

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

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo 📊✨

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay