# Blueprintの実体化について

**URL:** <https://forums.unrealengine.com/t/blueprint/295847>\
**Category:** Blueprint\
**Tags:** unreal-engine, Blueprint, question\
**Created:** [October 11, 2014, 3:53am UTC](https://forums.unrealengine.com/t/blueprint/295847 "2014-10-11T03:53:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mishimatsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mishimatsu](https://forums.unrealengine.com/u/mishimatsu)\
**Post date:** [October 11, 2014, 3:53am UTC](https://forums.unrealengine.com/t/blueprint/295847/1 "2014-10-11T03:53:28Z")

</div>

親クラスがObjectのBlueprintクラスの実体化の方法がかわりません。  
親クラスがActorの場合には、SpawnActorで実体化できますが、それに当たるBlueprintのコマンドは何になるのでしょうか？  
他の言語でいうとnewに当たるものです。

親クラスがObjectの独自BlueprintクラスをActorなどの別のクラスのメンバ変数として持っておき、利用したいのですが、実体化されていないので(noneになっている)、そのBlueprintのメンバー関数にアクセスすることができない状態です。

よろしくお願いいたします。

 ![17626-ue4instance00.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/2/5/f25f9452c644508fe9ec7d281c83d1c056143ae1.png)

 ![17627-ue4instance01.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/d/e/dde471695370931d8bcb0d4b1b1ef9c0629216a4.png)

---

<div class="post-metadata">

**Author:** ![sgkz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sgkz](https://forums.unrealengine.com/u/sgkz)\
**Post date:** [October 14, 2014, 5:36am UTC](https://forums.unrealengine.com/t/blueprint/295847/2 "2014-10-14T05:36:30Z")

</div>

ビルトインのコマンドとしては存在しないようなので、ネイティブでカスタムノードを作成するしかなさそうです。

英語ですが以下の記事が参考になると思います。

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

UE3ではスクリプトからobjectの派生クラス(非actor)もnewできたので、UE4でもそのうち純正のコマンドが用意されるのでは、と思っているのですが…

参考になれば幸いです。

---

<div class="post-metadata">

**Author:** ![mishimatsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mishimatsu](https://forums.unrealengine.com/u/mishimatsu)\
**Post date:** [October 14, 2014, 12:11pm UTC](https://forums.unrealengine.com/t/blueprint/295847/3 "2014-10-14T12:11:41Z")

</div>

回答ありがとうございます。  
現状できないことがわかったのは、本当にありがたいです。  
教えていただいた情報をもとに作ってみたいと思います。

ありがとうございました。

---

<div class="post-metadata">

**Author:** ![mishimatsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mishimatsu](https://forums.unrealengine.com/u/mishimatsu)\
**Post date:** [October 15, 2014, 1:19pm UTC](https://forums.unrealengine.com/t/blueprint/295847/4 "2014-10-15T13:19:03Z")

</div>

無事にカスタムノードを作成することができました。  
情報有り難うございました。

 ![17962-ue4+create0001.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/d/fbdfa2de5ffaeadfc13cad0e32f873a7ea703ee9.png)

---

<div class="post-metadata">

**Author:** ![sgkz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sgkz](https://forums.unrealengine.com/u/sgkz)\
**Post date:** [October 16, 2014, 7:11am UTC](https://forums.unrealengine.com/t/blueprint/295847/5 "2014-10-16T07:11:49Z")

</div>

解決できたようでよかったです。

ただ今こちらでも試してみたのですが、記事のコードのままだとactorを継承したクラスを指定するとゲーム終了時にクラッシュしてしまいますね。。それに第一引数も使っていないようなので整理すると以下のような感じになりそうですね。

```
UObject* UCreateNewObject::NewObjectFromBlueprint(TSubclassOf<UObject> UC)
{
    if ( UC->IsChildOf( AActor::StaticClass() ) ) return NULL;

    return StaticConstructObject(UC);
}

```

またメンバ変数の値を取得するのが目的であれば、newする代わりにデフォルト値を取得するカスタムノードを作成するという手もあります。

```
//.h
UCLASS()
class TESTAPP_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_UCLASS_BODY()

	UFUNCTION(BlueprintPure, Category = "Class|DefaultProperty")
	static bool GetClassDefaultPropertyEnumAsByte(UBlueprint* inBPClass, const FString& inProperty, uint8& outResult);	
};

//.cpp
bool UMyBlueprintFunctionLibrary::GetClassDefaultPropertyEnumAsByte(UBlueprint* inBPClass, const FString& inProperty, uint8& outResult)
{
	if ( !(inBPClass && inBPClass->GeneratedClass) ) return false;

	UByteProperty* byte_prop = FindField<UByteProperty>( inBPClass->GeneratedClass, FName(*inProperty) );
	if ( !(byte_prop && byte_prop->Enum) ) return false;

	outResult = byte_prop->GetPropertyValue_InContainer( inBPClass->GeneratedClass->GetDefaultObject() );

	return true;
}

```

上記は指定したブループリントクラスの指定したメンバ変数(enum)のデフォルト値を取得するカスタムノードの例です。引数のuint8の部分とUBytePropertyの部分を変更すれば、他の型でも動作すると思います。

アクタをスポーンさせる前にデフォルト値によって条件判定をしたい場合に便利です。

こちらも何かの参考になれば幸いです。

 ![18089-2014-10-16_1547.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/a/2/ba2c52e2669526fdb66da9df5c29fd5f11f68da7.png)

---

<div class="post-metadata">

**Author:** ![mishimatsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mishimatsu](https://forums.unrealengine.com/u/mishimatsu)\
**Post date:** [October 16, 2014, 1:14pm UTC](https://forums.unrealengine.com/t/blueprint/295847/6 "2014-10-16T13:14:51Z")

</div>

ご丁寧に、追加の情報有り難うございます。  
今後の参考にさせていただいきます。

今までは、画面に表示しないような制御系のものもActorから派生させて、使っていたので、今回は、別の方法でやってみようと思い、このインスタンス化の問題がでてきました。  
今回の情報で、かなりスッキリBlueprintも書けるようになりました。  
本当にありがとうございました。  
Blueprintのロードマップを確認してみたところ、まだ、非Actorのインスタンス化については、対応がなさそうなので、現状の方法使いつつ、拡張していくことになりそうです。  
UE4側で対応してもらえるとマルチプラットフォームに展開した時に、安心して使えるので、ぜひ対応してもらいたいですね。
