Skip to content
Snippets Groups Projects
Commit 058d0a62 authored by Jonathan Ehret's avatar Jonathan Ehret
Browse files

improve AttachToBone setting

parent 9ab4d74c
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,38 @@ void UVAAbstractSourceComponent::TickComponent(const float DeltaTime, const ELev
}
void UVAAbstractSourceComponent::UpdateSkeletalMeshIfAttachToBone()
{
if (MovementSetting == EMovement::AttachToBone)
{
AActor* Owner = GetOwner();
bool bFoundSkelMesh = false;
while(!bFoundSkelMesh && Owner != nullptr)
{
TArray<UActorComponent*> MeshComponents = Owner->GetComponentsByClass(USkeletalMeshComponent::StaticClass());
for (UActorComponent* Component : MeshComponents)
{
USkeletalMeshComponent* MeshComp = Cast<USkeletalMeshComponent>(Component);
if (MeshComp && MeshComp->DoesSocketExist(FName(*BoneName)))
{
//found the right mesh component
SkeletalMeshComponent = MeshComp;
bFoundSkelMesh = true;
break;
}
}
Owner = Owner->GetAttachParentActor();
}
if (SkeletalMeshComponent == nullptr)
{
FVAUtils::OpenMessageBox("[UVASourceComponent::Initialize()]: Could not find bone " +
BoneName + ", using MoveWithObject instead.", true);
MovementSetting = EMovement::MoveWithObject;
}
}
}
void UVAAbstractSourceComponent::Initialize()
{
if (!FVAPlugin::GetUseVA() || bInitialized)
......@@ -130,25 +162,7 @@ void UVAAbstractSourceComponent::Initialize()
UpdateRate = ReceiverActorTmp->GetUpdateRate();
if (MovementSetting == EMovement::AttachToBone)
{
TArray<UActorComponent*> MeshComponents = GetOwner()->GetComponentsByClass(USkeletalMeshComponent::StaticClass());
for(UActorComponent* Component : MeshComponents)
{
USkeletalMeshComponent* MeshComp = Cast<USkeletalMeshComponent>(Component);
if(MeshComp && MeshComp->DoesSocketExist(FName(*BoneName)))
{
//found the right mesh component
SkeletalMeshComponent = MeshComp;
}
}
if (SkeletalMeshComponent == nullptr)
{
FVAUtils::OpenMessageBox("[UVASourceComponent::Initialize()]: Could not find bone " +
BoneName + ", using MoveWithObject instead.", true);
MovementSetting = EMovement::MoveWithObject;
}
}
UpdateSkeletalMeshIfAttachToBone();
SpawnPosition = GetOwner()->GetTransform().GetLocation();
......@@ -375,6 +389,7 @@ bool UVAAbstractSourceComponent::SetMovementSetting(const EMovement::Type NewMov
}
MovementSetting = NewMovementSetting;
UpdateSkeletalMeshIfAttachToBone();
UpdatePose();
return true;
......
......@@ -185,6 +185,7 @@ protected:
// initialize Sound Source with the settings set //
virtual void Initialize();
void UpdateSkeletalMeshIfAttachToBone();
void UpdatePose();
bool SetSignalSourceID(const std::string& ID);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment