LoginSignup
1
1

UE4のpluginをGPT4と一緒に作った!

Posted at

勘違いをしていた

前回
GPT4でc++ほぼ書けない人がwhisperAIを叩けるプラグインを作ってみた
を書いたのですが、これ正確にはプラグインではなくblueprint function libraryであって、pluginではありませんでした。すみません...
この状態では別のプロジェクトで使いまわすのにいちいちc++の追加をしなくてはいけなく面倒です。
ですのでデータをコピペするだけでいいプラグインの形にしました!

UE4のプラグイン系の記事がねええええ

これがこの記事を書いた理由です!現状あまり有効な記事が無いです。ポジTAさんのを参考にさせて頂きました。

そのままじゃだめらしいからGPT4に投げる

~BPLibrary.hと~BPLibrary.cppに処理を書くのですがまずはほとんど前回で書いた処理のまま書いてみた結果が以下です

error.
  [1/5] Module.whisper_API.cpp
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(10) : error C2079: 'Uwhisper_APIBPLibrary' ?? ?????`?? class 'WHISPER_API' ?Ŏg?p???Ă??܂??B
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(10) : error C2143: ?\???G???[: ';' ?? ':' ?̑O?ɂ????܂????B
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(10) : error C2059: ?\???G???[: ':'
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(10) : error C2059: ?\???G???[: 'public'
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(11) : error C2143: ?\???G???[: ';' ?? '{' ?̑O?ɂ????܂????B
   D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(11) : error C2447: '{': ?Ή??????֐??w?b?_?[???????܂??? (???`???̉????X?g?)
   D:/unreal/PLUGINTEST/Plugins/whisper_API/Source/whisper_API/Private/whisper_APIBPLibrary.cpp(4) : error C2027: ?F???ł??Ȃ??^ 'Uwhisper_APIBPLibrary' ???g?????Ă??܂??B

 //もっとエラーが続きますがここまで 

でこれをgpt4に丸投げしたのですが、ヘッダーファイルを忘却しているようなことを話始めました。
ここで思い出します。gpt4は8kのトークン制限があるため、バカ長いエラーを送ったことで最初の話を忘れている可能性が高いと考えました。ですのでエラーについて問うと

whisper_APIBPLibrary.h(10)でのエラーを解消することで以降のエラーも直る可能性があります

でかしたGPT4!エラーの意味がいまいちよくわかってなかったのですが10行名のエラーを直すといいらしいです。ですので

error.
D:\unreal\PLUGINTEST\Plugins\whisper_API\Source\whisper_API\Public\whisper_APIBPLibrary.h(10) : error C2079: 'Uwhisper_APIBPLibrary' ?? ?????`?? class 'WHISPER_API' ?Ŏg?p???Ă??܂??B

これだけ質問を編集して聞き直してみました。
まるで定期的に記憶を失くしてしまうラノベの主人公が最後に手にメモを残すようですね。

WHISPER_APIマクロが見つからないため、コンパイルエラーが発生しています。WHISPER_APIマクロを正しいものに置き換える必要があります。マクロは通常、プロジェクト名に基づいています。プラグインの名前がwhisper_APIであるため、マクロ名をWHISPER_API_APIに変更することで解決できます。
ヘッダーファイル(whisper_APIBPLibrary.h)を次のように更新してください。

whisper_APIBPLibrary.cpp
#pragma once

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

DECLARE_DYNAMIC_DELEGATE_TwoParams(FWhisperAPIResponseDelegate, bool, bWasSuccessful, FString, ResponseContent);

UCLASS()
class WHISPER_API_API Uwhisper_APIBPLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

public:
    UFUNCTION(BlueprintCallable, Category = "Whisper API")
    static void SendWhisperAPIRequestAsync(FString Token, FString FilePath, FWhisperAPIResponseDelegate ResponseDelegate);
};

こんな感じで返答が来ました!
でコンパイルするとエラーが出たのでそのままgpt4になげました。

error.
[3/5] UE4Editor-whisper_API-5206.lib
     ???C?u???? D:\unreal\PLUGINTEST\Plugins\whisper_API\Intermediate\Build\Win64\UE4Editor\Development\whisper_API\UE4Editor-whisper_API-5206.lib ?ƃI?u?W?F?N?g D:\unreal\PLUGINTEST\Plugins\whisper_API\Intermediate\Build\Win64\UE4Editor\Development\whisper_API\UE4Editor-whisper_API-5206.exp ???쐬??
  [4/5] UE4Editor-whisper_API-5206.dll
     ???C?u???? D:\unreal\PLUGINTEST\Plugins\whisper_API\Intermediate\Build\Win64\UE4Editor\Development\whisper_API\UE4Editor-whisper_API-5206.suppressed.lib ?ƃI?u?W?F?N?g D:\unreal\PLUGINTEST\Plugins\whisper_API\Intermediate\Build\Win64\UE4Editor\Development\whisper_API\UE4Editor-whisper_API-5206.suppressed.exp ???쐬??
  Module.whisper_API.cpp.obj : error LNK2019: ???????̊O???V???{?? "__declspec(dllimport) public: static class FHttpModule & __cdecl FHttpModule::Get(void)" (__imp_?Get@FHttpModule@@SAAEAV1@XZ) ???֐? "public: static void __cdecl Uwhisper_APIBPLibrary::SendWhisperAPIRequestAsync(class FString,class FString,class FWhisperAPIResponseDelegate)" (?SendWhisperAPIRequestAsync@Uwhisper_APIBPLibrary@@SAXVFString@@0VFWhisperAPIResponseDelegate@@@Z) ?ŎQ?Ƃ????܂???
    ???`?ς݂̈??v?????”\?????????V???{???Ɋւ????q???g:
      "__declspec(dllimport) public: static class FObjectInitializer & __cdecl FObjectInitializer::Get(void)" (__imp_?Get@FObjectInitializer@@SAAEAV1@XZ)
      "__declspec(dllimport) public: class UObject * __cdecl FWeakObjectPtr::Get(void)const " (__imp_?Get@FWeakObjectPtr@@QEBAPEAVUObject@@XZ)
  D:\unreal\PLUGINTEST\Plugins\whisper_API\Binaries\Win64\UE4Editor-whisper_API-5206.dll : fatal error LNK1120: 1 ???̖??????̊O???Q??

このリンクエラーは、FHttpModuleクラスに関連するオブジェクトファイルがリンクされていないために発生しています。この問題を解決するには、whisper_API.Build.cs ファイルで HTTP モジュールをリンクするように指定する必要があります。
whisper_API.Build.cs ファイルを開き、以下の変更を行ってください:

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

こう返答があったのですが、これ多分普通のblueprint function libraryを作る時のやつで今回はpluginなので違うんじゃねって思いました。で、visual studioで見たとき階層的にこれしかないだろっていうbuild.csがあったので送ってみました。(どこを書き換えればいいのか分からなかった)
すると

元の whisper_API.Build.cs ファイルに HTTP モジュールが含まれていませんでした。このモジュールを追加することで、リンクエラーが解決されるはずです。
whisper_API.Build.cs ファイルを以下のように更新してください:

build.cs
using UnrealBuildTool;

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

        PublicIncludePaths.AddRange(
            new string[] {
                // ... add public include paths required here ...
            }
            );

        PrivateIncludePaths.AddRange(
            new string[] {
                // ... add other private include paths required here ...
            }
            );

        PublicDependencyModuleNames.AddRange(
            new string[]
            {
                "Core",
                "HTTP",
                // ... add other public dependencies that you statically link with here ...
            }
            );

        PrivateDependencyModuleNames.AddRange(
            new string[]
            {
                "CoreUObject",
                "Engine",
                "Slate",
                "SlateCore",
                // ... add private dependencies that you statically link with here ...
            }
            );

        DynamicallyLoadedModuleNames.AddRange(
            new string[]
            {
                // ... add any modules that your module loads dynamically here ...
            }
            );
    }
}

PublicDependencyModuleNames の配列に "HTTP" を追加しました。プロジェクトをリビルドし、リンクエラーが解決されているか確認してください。

おお!コンパイル通りました!

まとめ

gp4君はネット上にほぼデータがないマイナーなものは自己完結するのは難しいですが、足りない思考力とデータを補ってあげれば十分に使えると思いました!

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