LoginSignup
7
5

More than 5 years have passed since last update.

UE4でゲームパッドに接続されているか認識する方法

Last updated at Posted at 2017-05-21

はじめに

初めまして。Neetpiaです。
現在、幻想郷ディフェンダーズというアクションタワーディフェンスをWindows/PlayStation4向けに開発しています。

幻想郷ディフェンダーズ

このゲームですが、マウスとゲームパッド両方の操作に対応しています。
それだけならいいのですが、ゲームパッドが接続している場合、画面の表記が変化します。

例えば、早送りの表記です。
image.png

そのため、ゲームパッドを識別する必要があります。
ただ、検索しても資料がなかったので、ここで説明します。

認識方法

たったこれだけです。
SlateCoreモジュールを依存に追加する必要があります。

bool IsGamePadConnected()
{
    auto genericApplication = FSlateApplication::Get().GetPlatformApplication();
    if (genericApplication.Get() != nullptr &&
        genericApplication->IsGamepadAttached())
    {
        return true;
    }

    return false;
}

BluePrintには公開されていないようなので、C++で記述してBluePrintでも使用できるようにすると楽です。

UFUNCTION(BlueprintCallable)
static bool IsGamePadConnected();

UE4.14で使用できることを確認しました。


今後、少しずつ、幻想郷ディフェンダーズの開発で得たノウハウを公開していこうと思います。

7
5
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
7
5