Skip to content
Snippets Groups Projects
Commit 5d0f6c91 authored by Konstantin Kühlem's avatar Konstantin Kühlem
Browse files

feat(VirtualHuman): Add BlueprintCallable method to force a reselect of the IDLE animation

parent c8e4bd89
No related branches found
No related tags found
No related merge requests found
......@@ -168,6 +168,16 @@ bool AVirtualHuman::SupportsMorphs()
return BodyType != EBodyType::MetaHuman;
}
bool AVirtualHuman::ForcePlayNewIdleAnimation()
{
if (CustomIdleAnimations.IsEmpty()) return false;
NextIdleTimerHandle.Invalidate();
PlayRandomIdleAnimation();
return true;
}
void AVirtualHuman::SetUpBodyType()
{
if (BodyType == EBodyType::CC3)
......@@ -315,12 +325,11 @@ void AVirtualHuman::PlayRandomIdleAnimation()
}
// play random idle animation
int Random = IdleRandomStream.RandRange(0, CustomIdleAnimations.Num() - 1);
UAnimSequence* IdleAnim = CustomIdleAnimations[Random];
if (IdleAnim)
const int Random = IdleRandomStream.RandRange(0, CustomIdleAnimations.Num() - 1);
if (UAnimSequence* IdleAnim = CustomIdleAnimations[Random])
{
float BlendTime = 0.25f;
UAnimMontage* DynamicMontage = GetBodyAnimInstance()->PlaySlotAnimationAsDynamicMontage(
const float BlendTime = 0.25f;
const UAnimMontage* DynamicMontage = GetBodyAnimInstance()->PlaySlotAnimationAsDynamicMontage(
IdleAnim, "CustomIdleSlot", BlendTime, BlendTime);
// start timer for next random pick (make it a bit shorter to allow for blending, but only by a defined minimal amount for the animations)
GetWorld()->GetTimerManager().SetTimer(NextIdleTimerHandle, this, &AVirtualHuman::PlayRandomIdleAnimation,
......
......@@ -96,6 +96,15 @@ public:
virtual EVHGender GetGender();
virtual bool SupportsMorphs();
/**
* Forces a new IDLE animation to be played, which is randomly chosen from "CustomIdleAnimations".
* Note that the new animation might also be the one which is currently playing.
* This method is useful, e.g. if the "CustomIdleAnimations" change.
* @return true, if a animation was select (might be false, if "CustomIdleAnimations" is empty)
*/
UFUNCTION(BlueprintCallable)
bool ForcePlayNewIdleAnimation();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
......@@ -112,11 +121,11 @@ protected:
UPROPERTY(EditAnywhere, meta = (EditCondition = "BodyType==BodyType::MetaHuman"))
TSubclassOf<UVHAnimInstance> FaceAnimInstanceToUse;
//custom idle animations can be specified to be used (played in the DefualtSlot)
//custom idle animations can be specified to be used (played in the DefaultSlot)
//CAUTION: this currently does not work together with walking or pointing
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualHuman|Custom Idle Animations")
TArray<UAnimSequence*> CustomIdleAnimations;
//The minimal percentage of the animation that is allowed to be skiped to blend into another animation
//The minimal percentage of the animation that is allowed to be skipped to blend into another animation
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "VirtualHuman|Custom Idle Animations")
float MinBlendTime = 1.0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment