C++で作成したコンポーネントをアタッチしたBlueprintクラスがあります。
このBPが持つconstruction scriptは、プロパティに変更があるたびに呼び出されます。
プロパティが変更されたときに行いたい作業はないため、BP内のconstruction scriptには何も実装していません。
ただし、アタッチされたC++の自作コンポーネントもコンストラクタが毎回呼ばれます。
確認してみると、インスタンスが初期化(アドレスが変わっている)されコンストラクタが呼ばれているようです。
`UMyComponent::UMyComponent()
{
UE_LOG(LogTemp, Log, TEXT(“Component constructor: %p”), this);
}`上記のコンポーネントがついたアクタを動かしたときのログがアタッチされたファイルです。
そのうえで2つ質問があります。
Q1.
なぜコンポーネントはBPクラスのプロパティが変更されるたび初期化されるのでしょうか?
Q2.
C++側のコンポーネントを実行したいのは、アクタがレベルにスポーンしたときだけで、プロパティに変更があるたびに初期化されたくありません。
プロパティが変更されてもコンポーネントの実体を同じにすることはできますか?
Hi [mention removed]
When a variable is modified, it is intended the the component is fully reconstructed. The Actor Blueprint triggers FBlueprintEditor::PostEditChangeProperty that is called when a Blueprint variable is modified inside a Blueprint. This ends up calling AActor::RerunConstructionScripts and for Blueprint components the object is reconstructed. The actor explicitly unregister all components, spawns them again and registers them:
ActorEditor.cpp line 237-239 in version 5.6.
UnregisterAllComponents(); RerunConstructionScripts(); ReregisterAllComponents();
I’ve seen another users ask this same question and currently there is no direct supported way to not reconstruct the entire Blueprint.
Workarounds:
1- If you initialize your ActorComponent from C++ it won’t reconstruct the ActorComponent as it is not attached directly to the BlueprintAsset. So if you don’t want your ActorComponent to be reconstructed on each property modification, create it directly from c++ using CreateDefaultSubobject.
2- The actor component is reconstructed because the Actor detects a modification of the property via AActor::PostEditChangeProperty. I’ve seen some engine source code in some Epic plugins disable the full reconstruction of the blueprint actor components. But this is a more complex solution as you need to copy the AActor::PostEditChange code and modify it, so that it adds the functionality you want. So by overriding AActor::PostEditChange and implement it you own, you could achieve what you want, but it requires more work.
Hope I could guide you a bit, let me know if the answer solved your doubt.
Best regards,
Joan
ご回答、ありがとうございます!
こちら解決しましたので、closeして頂ければと思います