LoginSignup
0
0

AnimationMontage再生中に中断されたときに呼び出されるデリゲート【UnrealC++】

Posted at

概要

AnimationMontage再生中に中断されたときに呼び出されるデリゲートの実装方法についての忘備録
(※エンジンのソースコードを読むことにまだ慣れていないので記事の内容が適切じゃない可能性があります。)

実装するにあたって以下の3つを使用します。
・FOnMontageEnded
・CompleteDelegate.BindWeakLambda()
・Montage_SetEndDelegate()

サンプルコード

.cpp
	UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
	FOnMontageEnded CompleteDelegate; // デリゲート
	if (AnimInstance && ReloadMontage)
	{
		AnimInstance->Montage_Play(ReloadMontage);
		FName SectionName = FName("Reload");;
		AnimInstance->Montage_JumpToSection(SectionName);

		/*
        * AnimationMontageが中断した場合の処理
        * (例えばリロードアニメーション中に攻撃を受けたときリロードアニメーションを中断する実装をしている場合、
        * AnimationMontageで設定していたAnimNotifyが呼ばれなくなる問題に対応できる)
        */
		CompleteDelegate.BindWeakLambda(this, [this](UAnimMontage* animMontage, bool bInterrupted)->void
			{
				if (bInterrupted)
				{
					// アニメーションが中断した時
				}
				else
				{
					// アニメーションが問題なく終了した時
				}
			});
	}
    /*
    * ブロードキャストする
    * (BindWeakLambda内のanimMontageとbInterruptedはFAnimMontageInstance::Stopの中のInst->QueueMontageBlendingOutEventで設定されている)
    * (Broadcast自体はUAnimInstance::TriggerMontageEndedEvent()の中で行っている)
    */
	AnimInstance->Montage_SetEndDelegate(CompleteDelegate, ReloadMontage);

0
0
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
0
0