Files
UnrealEngineUWP/Engine/Source/Editor/AnimationModifiers/Public/AnimationModifiersAssetUserData.h
Jurre deBaare a5305f76a3 Contributed by Yupeng.Zhang from The Coalition:
Animation Modifier : Fix Modifier on Skeleton
Transfered the ownership of 'PreviouslyAppliedModifier' from an animation modifier instance to the animation sequence being applied.
This solved the following issue:
- Modifier on Skeleton cause USkeleton dirtied everytime the modifier is applied to an animation sequence.
- Modifier on Skeleton cannot be re-apply or reverted correctly.
- CanRevert & OutOfDate status for Modifier on Skeleton was not reflect the true status of all animation sequences referencing that skeleton.

- CurrentAnimSequence/CurrentSkeleton was not set on OnRevert()
- IAnimationDataController::FScopedBracket was not open on OnRevert() before re-apply modifier
- Stateful animation modifier can now be reverted correctly (Applied modifier instance is nolonger reverted after OnApply call)

#preflight 63775e0ff514e1ded99ef095

[CL 23191977 by Jurre deBaare in ue5-main branch]
2022-11-18 05:35:47 -05:00

74 lines
2.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Engine/AssetUserData.h"
#include "HAL/Platform.h"
#include "UObject/ObjectMacros.h"
#include "UObject/ObjectPtr.h"
#include "UObject/UObjectGlobals.h"
#include "AnimationModifiersAssetUserData.generated.h"
class FArchive;
class UAnimationModifier;
class UObject;
template <typename T> struct TObjectPtr;
/** Asset user data which can be added to a USkeleton or UAnimSequence to keep track of Animation Modifiers */
UCLASS()
class ANIMATIONMODIFIERS_API UAnimationModifiersAssetUserData : public UAssetUserData
{
GENERATED_BODY()
friend class SAnimationModifiersTab;
friend class SAnimationModifierContentBrowserWindow;
friend class FAnimationModifiersModule;
friend class UAnimationModifier;
public:
const TArray<UAnimationModifier*>& GetAnimationModifierInstances() const;
protected:
/** Begin UAssetUserData overrides */
virtual void PostLoad() override;
virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
virtual void Serialize(FArchive& Ar) override;
#if WITH_EDITOR
virtual void PostEditChangeOwner() override;
#endif // WITH_EDITOR
/** End UAssetUserData overrides */
void AddAnimationModifier(UAnimationModifier* Instance);
void RemoveAnimationModifierInstance(UAnimationModifier* Instance);
void ChangeAnimationModifierIndex(UAnimationModifier* Instance, int32 Direction);
private:
void RemoveInvalidModifiers();
protected:
UPROPERTY()
TArray<TObjectPtr<UAnimationModifier>> AnimationModifierInstances;
// Animation modifiers APPLIED on the owning animation sequence
//
// - Key = Modifier in AnimationModifierInstances of owning animation sequence or skeleton
// - Value = Modifier instance applied
//
// Applied modifier instances stores (Properties, RevisionGuid, ...) at Apply Time
// Which are not visible or editable from user interface
//
// In contrast, modifiers in AnimationModifierInstances
// are objects displayed at the Animation Data Modifier window
// Where Properties are displayed for user editing anytime
//
// Note, Modifier on Skeleton (MoS) applied instances are stored on each
// animation sequence's asset user data, instead of the skeleton's
// this design is important to enable applied modifiers can be reverted for each sequence
// also ensure applying MoS (when [re]importing animation) will not affect the skeleton asset
//
// The only time MoS stores an applied instance here is upgrading from previous version
// The "UAnimationModifier::PreviouslyAppliedModifier_DEPRECATED" data will be migrated here
// To support proper revert for them
// For more compatibility handling, check UAnimationModifier::PostLoad() and GetAppliedModifier()
UPROPERTY()
TMap<FSoftObjectPath, TObjectPtr<UAnimationModifier>> AppliedModifiers;
};