LoginSignup
2
4

More than 5 years have passed since last update.

UE4プラグインビルド時に対処したネタ集

Posted at

備忘録として。あまりプラグインは関係ないかも。

UE4でwindows.hを利用する

win.cpp
#if PLATFORM_WINDOWS

//最低限であればこちら
#include "Windows/WindowsSystemIncludes.h"

//全部読むならこちら
#include "AllowWindowsPlatformTypes.h"
#include <windows.h>
#include "HideWindowsPlatformTypes.h"
#endif

実装例はよく見かける。元ネタは不明…

外部ライブラリに日本語パスを渡す

外部ライブラリでファイルが読めなかった時の対処。
FPathsやFStringに格納されているパスを、そのままstd::stringに渡すと読めないことがあった。

変換にWideCharToMultiByteを利用すると読めた。windows.hが必要。
https://qiita.com/yumetodo/items/453d14eff41b805d8fc4

UE4のマクロは色々あるが、どれも駄目だった。あまり深追いしていない。
http://api.unrealengine.com/INT/Programming/UnrealArchitecture/StringHandling/CharacterEncoding/index.html

プラグインを他のプラグインに依存させる

MyPlugin.uplugin
{
  "FileVersion": 3,
  "Version": 1,
  "VersionName": "1.0",
  "FriendlyName": "test",
  "Description": "",
  "Category": "Rendering",
  "CreatedBy": "",
  "CreatedByURL": "",
  "DocsURL": "",
  "MarketplaceURL": "",
  "SupportURL": "",
  "EnabledByDefault" : true,
  "CanContainContent": true,
  "IsBetaVersion": false,
  "Installed": false,
  "Modules": [
    {
      "Name": "MyPlugin",
      "Type": "Runtime",
      "LoadingPhase": "PreDefault"
    },
  ],
↓↓↓↓↓ これを追加する
  "Plugins": [
     {
       "Name": "ProceduralMeshComponent",
       "Enabled": true
     }
 ]
↑↑↑↑↑
}

参考:
https://answers.unrealengine.com/questions/745416/plugins-can-not-user-another-plugins.html

コマンドラインでUE4バージョンを切り替えてビルドする

複数のUE4バージョンを対象にしたプラグインを作成するために。

手順まとめ

.uprojectのEngineAssociationを書き換えた後、UnrealVersionSelector.exeでslnを作り直す

MyGame.uproject
{
    "FileVersion":  3,
    "EngineAssociation":  "4.19",   ← ここを書き換える
    "Category":  "",
    "Description":  "",
    "Enterprise":  false,
    "Modules":  [
        {
            "Name":  "MyGame",
            "Type":  "Runtime",
            "LoadingPhase":  "Default"
        }
    ]
}

具体的な手順

以下のようなスクリプトを作成して、

changeEngineVer.ps1
$a = Get-Content ./MyGame.uproject -Encoding UTF8 | ConvertFrom-Json

$a.EngineAssociation = $Args[0]

$a | ConvertTo-Json > ./MyGame.uproject

batファイルから呼び出す

change.bat
powershell -ExecutionPolicy RemoteSigned .\changeEngineVer.ps1 \"4.20%\"

sln作り直す

generate.bat
set UNREALVERSIONSELECTOR="C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe"
UNREALVERSIONSELECTOR /projectfiles MyGame.uproject

なぜGenerateProjectFiles.batが削除されたんだ? 不便になった。

参考:
https://usagi.hatenablog.jp/entry/2017/10/27/074110
https://answers.unrealengine.com/questions/275271/change-the-engine-version-of-a-project-via-command.html
https://qiita.com/cd01/items/82829ba0ec0f59e1b04d
https://win.just4fun.biz/?PowerShell/%E3%83%8F%E3%83%83%E3%82%B7%E3%83%A5%E3%81%8B%E3%82%89JSON%2CJSON%E3%81%8B%E3%82%89PSCustomObject%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95

2
4
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
2
4