UE5/UE4 C++でコンストラクションスクリプト(Construction Script)を実行する(OnConstruction)
C++でコンストラクションスクリプト(Construction Script)を実行する方法です。
こちらを参考にさせていただきました。
・【UE4】ConstructionScriptについて【★★】
https://kinnaji.com/2021/02/09/aboutconstructionscript/
公式ドキュメントはこちら。
・コンストラクション スクリプト(Construction Script)
https://docs.unrealengine.com/4.27/ja/ProgrammingAndScripting/Blueprints/UserGuide/UserConstructionScript/
というわけで、実際に「コンストラクションスクリプト(Construction Script)」を実行するためのクラスを作成します。
実体の方はこんな感じになります。
これでコンストラクションスクリプトを実行する処理は完了です。
アクターに変更が起きた場合に自動で何かしたいなど結構ありそうなので、色々と使えるのかなと思います。
こちらを参考にさせていただきました。
・【UE4】ConstructionScriptについて【★★】
https://kinnaji.com/2021/02/09/aboutconstructionscript/
公式ドキュメントはこちら。
・コンストラクション スクリプト(Construction Script)
https://docs.unrealengine.com/4.27/ja/ProgrammingAndScripting/Blueprints/UserGuide/UserConstructionScript/
というわけで、実際に「コンストラクションスクリプト(Construction Script)」を実行するためのクラスを作成します。
このクラスの「OnConstruction」という関数がコンストラクションスクリプトに該当します。// コンストラクションスクリプト(Construction Script)を実装するクラス
class ANewActor : public AActor
{GENERATED_BODY()public:// コンストラクタ
ANewActor ();public:virtual void BeginPlay() override;};
virtual void EndPlay( const EEndPlayReason::Type EndPlayReason ) override;
virtual void Tick( float DeltaTime ) override;
// コンストラクション
virtual void OnConstruction(const FTransform& Transform) override;
実体の方はこんな感じになります。
// コンストラクション
void ANewActor ::OnConstruction(const FTransform& Transform)
{Super::OnConstruction(Transform);#if WITH_EDITOR// エディタのみで実行される処理など#endif}
これでコンストラクションスクリプトを実行する処理は完了です。
アクターに変更が起きた場合に自動で何かしたいなど結構ありそうなので、色々と使えるのかなと思います。
| UE5 | 10:00 | comments:0 | trackbacks:0 | TOP↑