LoginSignup
0

More than 1 year has passed since last update.

UnrealEngineでアセットのパス文字列で指定したBlueprintClassのインスタンスを作成する

Posted at

アセットのパス文字列で指定したBlueprintClassからインスタンスを作成するやり方をメモしておきます。
iniでSpawnするアクタを指定して切り替えるようなことができます。
以下の例はActorですがWidgetなどでも応用可能です。

UE4.27.2で動作確認しています。
もっと良い実装方法があったら教えてください。

以下のようなC++を用意

MyBlueprintFunctionLibrary.h
UFUNCTION(BlueprintCallable)
static UClass* StaticLoadClassFromSring(FString Path);
MyMyBlueprintFunctionLibrary.cpp
UClass* UMyBlueprintFunctionLibrary::StaticLoadClassFromSring(FString Path)
{
	UClass* Class = StaticLoadClass(UObject::StaticClass(), nullptr, *Path);
	if (!Class)
	{
		UE_LOG(LogTemp, Error, TEXT("Failed o load class at path:%s"), *Path);
	}
	return Class;
}

以下のように用意したノードを利用

loadclass.png

パッケージング時の設定

ちゃんと検証していませんが、場合によっては以下の設定に読み込みたいアセットが入ったディレクトリを指定しておく必要があるかもしれません。
[Project Settings] > [Packaging] > [Additional Asset Directories to Cook]

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
0