Ejemplo n.º 1
0
/** Play a Montage. Returns Length of Montage in seconds. Returns 0.f if failed to play. */
float UAnimInstance::Montage_Play(UAnimMontage * MontageToPlay, float InPlayRate)
{
	if( MontageToPlay && (MontageToPlay->SequenceLength > 0.f) ) 
	{
		if( CurrentSkeleton->IsCompatible(MontageToPlay->GetSkeleton()) )
		{
			// when stopping old animations, make sure it does give current new blendintime to blend out
			StopAllMontages(MontageToPlay->BlendInTime);

			FAnimMontageInstance * NewInstance = new FAnimMontageInstance(this);
			check (NewInstance);

			NewInstance->Initialize(MontageToPlay);
			NewInstance->Play(InPlayRate);
			MontageInstances.Add(NewInstance);

			UpdateRootMotionMontageInstance();

			return NewInstance->Montage->SequenceLength;
		}
		else
		{
			UE_LOG(LogAnimation, Warning, TEXT("Playing a Montage (%s) for the wrong Skeleton (%s) instead of (%s)."), 
				*GetNameSafe(MontageToPlay), *GetNameSafe(MontageToPlay->GetSkeleton()), *GetNameSafe(CurrentSkeleton));
		}
	}
	else
	{
		UE_LOG(LogAnimation, Warning, TEXT("Trying to play invalid Montage (%s)"), *GetNameSafe(MontageToPlay));
	}

	return 0.f;
}
Ejemplo n.º 2
0
void UAnimSingleNodeInstance::SetAnimationAsset(class UAnimationAsset* NewAsset,bool bIsLooping,float InPlayRate)
{
	if (NewAsset != CurrentAsset)
	{
		CurrentAsset = NewAsset;
	}

	if (USkeletalMeshComponent * MeshComponent = GetSkelMeshComponent())
	{
		if (MeshComponent->SkeletalMesh == NULL)
		{
			// if it does not have SkeletalMesh, we nullify it
			CurrentAsset = NULL;
		}
		else if (CurrentAsset != NULL)
		{
			// if we have an asset, make sure their skeleton matches, otherwise, null it
			if (CurrentSkeleton != CurrentAsset->GetSkeleton())
			{
				// clear asset since we do not have matching skeleton
				CurrentAsset = NULL;
			}
		}
	}

	bLooping = bIsLooping;
	PlayRate = InPlayRate;
	CurrentTime = 0.f;
	BlendSpaceInput = FVector::ZeroVector;
#if WITH_EDITORONLY_DATA
	PreviewPoseCurrentTime = 0.0f;
#endif

	UAnimMontage* Montage = Cast<UAnimMontage>(CurrentAsset);
	if ( Montage!=NULL )
	{
		ReinitializeSlotNodes();
		if ( Montage->SlotAnimTracks.Num() > 0 )
		{
			RegisterSlotNodeWithAnimInstance(Montage->SlotAnimTracks[0].SlotName);
		}
		RestartMontage( Montage );
		SetPlaying(bPlaying);
	}
	else
	{
		// otherwise stop all montages
		StopAllMontages(0.25f);

		UBlendSpaceBase * BlendSpace = Cast<UBlendSpaceBase>(CurrentAsset);
		if(BlendSpace)
		{
			BlendSpace->InitializeFilter(&BlendFilter);
		}
	}
}
void UAnimSingleNodeInstance::SetAnimationAsset(class UAnimationAsset* NewAsset,bool bIsLooping,float InPlayRate)
{
	if (NewAsset != CurrentAsset)
	{
		CurrentAsset = NewAsset;
	}

	if (USkeletalMeshComponent * MeshComponent = GetSkelMeshComponent())
	{
		if (MeshComponent->SkeletalMesh == NULL)
		{
			// if it does not have SkeletalMesh, we nullify it
			CurrentAsset = NULL;
		}
		else if (CurrentAsset != NULL)
		{
			// if we have an asset, make sure their skeleton matches, otherwise, null it
			if (CurrentSkeleton != CurrentAsset->GetSkeleton())
			{
				// clear asset since we do not have matching skeleton
				CurrentAsset = NULL;
			}
		}
	}

	bLooping = bIsLooping;
	PlayRate = InPlayRate;
	CurrentTime = 0.f;
#if WITH_EDITORONLY_DATA
	PreviewPoseCurrentTime = 0.0f;
#endif

	UAnimMontage* Montage = Cast<UAnimMontage>(CurrentAsset);
	if ( Montage!=NULL )
	{
		ActiveSlotWeights.Empty();
		if ( Montage->SlotAnimTracks.Num() > 0 )
		{
			RegisterSlotNode(Montage->SlotAnimTracks[0].SlotName);
		}
		RestartMontage( Montage );
	}
	else
	{
		// otherwise stop all montages
		StopAllMontages(0.25f);
	}
}