0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【UE5】【C++】C++からWidgetのアニメーションを再生する

0
Posted at

「BindWidgetAnim」を使用する場合

.h
UCLASS()
class NIGHT_API UNT_Interact : public UUserWidget
{
	GENERATED_BODY()

public:
	void NativeConstruct() override;

private:
    //BPのアニメーション名を「MoveAnime」と変数名と同じにする必要がある
	UPROPERTY(Transient, meta = (BindWidgetAnim))
	TObjectPtr<UWidgetAnimation> MoveAnime;
};

//============================
.cpp

void UNT_Interact::NativeConstruct()
{
    //アニメーション開始
	PlayAnimation(MoveAnime);
}

「変数名」と「アニメーション名」を完全一致しないとエラーが表示されるので注意してください

スクリーンショット 2026-07-30 235626.png

「BlueprintNativeEvent」を使用する場合

.h
UCLASS()
class NIGHT_API UNT_Interact : public UUserWidget
{
	GENERATED_BODY()

public:
	//Blueprintから中身を上書きする
	UFUNCTION(BlueprintNativeEvent)
	UWidgetAnimation* GetMoveAnime() const;
	virtual UWidgetAnimation* GetMoveAnime_Implementation() const { return nullptr; }

	void NativeConstruct() override;

private:
	UPROPERTY()
	TObjectPtr<UWidgetAnimation> MoveAnime;
};

//============================
.cpp

void UNT_Interact::NativeConstruct()
{
    MoveAnime = GetMoveAnime();

	if (MoveAnime)
	{
        //アニメーション開始
		PlayAnimation(MoveAnime);
	}
}

BPから関数をOverrideします。

スクリーンショット 2026-07-30 235817.png

再生するアニメーションをReturnに繋いでだけです。
b1.gif

自分はこの2つしか思いつきませんでした。
他に効率的な方法などがあったら教えてください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?