UE 动画编辑器扩展

简单扩展一下ue的动画编辑器,让它能够根据动画通知在编辑器内实时预览修改的后处理效果。


大致效果如下


起初直接获取Viewport,然后调用"OverridePostProcessSettings",结果没有生效,之后发现要修改PostProcessVolume才可以,因此需要用到下面这个函数

用的时候通过动画通知内的MeshComp来获取编辑器的World然后再调用即可。

MeshComp->GetWorld()->InsertPostProcessVolume(PostProcessComponent);

我这里直接新建了一个UPostProcessComponent,修改后处理效果后加上去会导致在动画通知内开始结束游戏崩溃,所以还需要调用一下AddToRoot()


// .h

#pragma once
#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotifyState.h"
#include "Components/PostProcessComponent.h"
#include "ANS_EditorPP.generated.h"
/**
 */

UCLASS()
class EMEDITOR_API UANS_EditorPP : public UAnimNotifyState
{
	GENERATED_BODY()
public:

	UFUNCTION(BlueprintCallable, Category = "Editor Camera")
		void InsertPostProcessEditor(FPostProcessSettings PostProcessSettings, USkeletalMeshComponent* MeshComp);
	UFUNCTION(BlueprintCallable, Category = "Editor Camera")
		void RemovePostProcessEditor(USkeletalMeshComponent* MeshComp);

	UPostProcessComponent* PostProcessComponent;

};


// .cpp

#include "Common/ANS_EditorPP.h"


void UANS_EditorPP::RemovePostProcessEditor(USkeletalMeshComponent* MeshComp)
{
	if (MeshComp)
	{
		MeshComp->GetWorld()->RemovePostProcessVolume(PostProcessComponent);
		//UE_LOG(LogTemp, Warning, TEXT("%d"), MeshComp->GetWorld()->PostProcessVolumes.Num());
	}
}

void UANS_EditorPP::InsertPostProcessEditor(FPostProcessSettings PostProcessSettings, USkeletalMeshComponent* MeshComp)
{
	PostProcessComponent = NewObject<UPostProcessComponent>();
	PostProcessComponent->Settings = PostProcessSettings;
	PostProcessComponent->AddToRoot();

	if(MeshComp)
	{
		MeshComp->GetWorld()->InsertPostProcessVolume(PostProcessComponent);
	}
}