diff --git a/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp b/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp index f6cf224e60291e64395746c7fe69db025f08a6e0..2aca4f5f495fba1f27b8f9e33fb228544f40f150 100644 --- a/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp +++ b/Source/VAPlugin/Private/SoundSource/VAAbstractSourceComponent.cpp @@ -20,7 +20,7 @@ UVAAbstractSourceComponent::UVAAbstractSourceComponent() { PrimaryComponentTick.bCanEverTick = true; - + //Default objects for subcomponents does not work //SignalSource = CreateDefaultSubobject<UVAAudiofileSignalSource>(TEXT("SignalSource"), false); } @@ -49,7 +49,7 @@ void UVAAbstractSourceComponent::EndPlay(const EEndPlayReason::Type EndPlayReaso // Called every frame void UVAAbstractSourceComponent::TickComponent(const float DeltaTime, const ELevelTick TickType, - FActorComponentTickFunction* ThisTickFunction) + FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); @@ -60,7 +60,7 @@ void UVAAbstractSourceComponent::TickComponent(const float DeltaTime, const ELev if (!bInitialized) { - if(!bInformedNotInitialized) + if (!bInformedNotInitialized) { FVAUtils::OpenMessageBox("[UVASourceComponent::TickComponent()]: Sound source is not initialized", true); bInformedNotInitialized = true; @@ -93,27 +93,28 @@ void UVAAbstractSourceComponent::UpdateSkeletalMeshIfAttachToBone() { AActor* Owner = GetOwner(); bool bFoundSkelMesh = false; - while(!bFoundSkelMesh && Owner != nullptr) + while (!bFoundSkelMesh && Owner != nullptr) { - TArray<UActorComponent*> MeshComponents = Owner->GetComponentsByClass(USkeletalMeshComponent::StaticClass()); - for (UActorComponent* Component : MeshComponents) + TArray<USkeletalMeshComponent*> MeshComponents; + Owner->GetComponents(MeshComponents); + for (USkeletalMeshComponent* Component : MeshComponents) { - USkeletalMeshComponent* MeshComp = Cast<USkeletalMeshComponent>(Component); - if (MeshComp && MeshComp->DoesSocketExist(FName(*BoneName))) + if (Component && Component->DoesSocketExist(FName(*BoneName))) { //found the right mesh component - SkeletalMeshComponent = MeshComp; + SkeletalMeshComponent = Component; bFoundSkelMesh = true; break; } } + Owner = Owner->GetAttachParentActor(); } if (SkeletalMeshComponent == nullptr) { - FVAUtils::OpenMessageBox("[UVASourceComponent::Initialize()]: Could not find bone " + - BoneName + ", using MoveWithObject instead.", true); + FVAUtils::OpenMessageBox("[UVASourceComponent::Initialize()]: Could not find bone " + + BoneName + ", using MoveWithObject instead.", true); MovementSetting = EMovement::MoveWithObject; } } @@ -138,7 +139,8 @@ void UVAAbstractSourceComponent::Initialize() // If no Rec Actor found spawn one with default parameters if (ReceiverActorTmp == nullptr) { - FVAUtils::LogStuff("[UVASourceComponent::BeginPlay()]: No AVAReceiver found! Spawning one with default values", false); + FVAUtils::LogStuff( + "[UVASourceComponent::BeginPlay()]: No AVAReceiver found! Spawning one with default values", false); ReceiverActorTmp = this->GetWorld()->SpawnActor<AVAReceiverActor>(AVAReceiverActor::StaticClass()); } } @@ -151,8 +153,12 @@ void UVAAbstractSourceComponent::Initialize() { FVAPlugin::SetUseVA(false); - FVAUtils::OpenMessageBox("There are more than 1 Receiver Actors in the world. Stopping VAPlugin. Make sure to remove the wrong one.", true); - FVAUtils::LogStuff("[UVASourceComponent::BeginPlay()]: More than 1 Receiver found! Stopping VAPlugin. Make sure to remove the wrong one", true); + FVAUtils::OpenMessageBox( + "There are more than 1 Receiver Actors in the world. Stopping VAPlugin. Make sure to remove the wrong one.", + true); + FVAUtils::LogStuff( + "[UVASourceComponent::BeginPlay()]: More than 1 Receiver found! Stopping VAPlugin. Make sure to remove the wrong one", + true); return; } @@ -169,9 +175,11 @@ void UVAAbstractSourceComponent::Initialize() SpawnRotation = GetOwner()->GetTransform().GetRotation().Rotator(); - const std::string ExplicitRendererID = bRendererExplicit ? std::string( TCHAR_TO_UTF8(*RendererID) ): ""; // Empty ID => general source - const std::string SoundSourceName = std::string( TCHAR_TO_UTF8(*GetName()) ); - SoundSource = MakeShared<FVASoundSource>(GetWorld(), GetPosition(), GetRotation(), SoundPower, SoundSourceName, ExplicitRendererID); + const std::string ExplicitRendererID = bRendererExplicit ? std::string(TCHAR_TO_UTF8(*RendererID)) : ""; + // Empty ID => general source + const std::string SoundSourceName = std::string(TCHAR_TO_UTF8(*GetName())); + SoundSource = MakeShared<FVASoundSource>(GetWorld(), GetPosition(), GetRotation(), SoundPower, SoundSourceName, + ExplicitRendererID); if (UVirtualRealityUtilities::IsMaster()) { @@ -234,7 +242,8 @@ bool UVAAbstractSourceComponent::SetSignalSourceID(const std::string& SignalSour { if (!SoundSource.IsValid()) { - FVAUtils::OpenMessageBox(FString("[UVASourceComponent::SetSignalSourceID]: VA sound source not initialized"), true); + FVAUtils::OpenMessageBox(FString("[UVASourceComponent::SetSignalSourceID]: VA sound source not initialized"), + true); return false; } if (!SoundSource->SetSignalSource(SignalSourceID)) @@ -309,7 +318,6 @@ bool UVAAbstractSourceComponent::GetHandleReflections() const } - // ****************************************************************** // // ******* Sound Pose *********************************************** // // ****************************************************************** // @@ -419,7 +427,7 @@ bool UVAAbstractSourceComponent::SetOffsetPosition(const FVector Pos) { return false; } - + if (OffsetPosition == Pos && bUsePoseOffset) { return true; @@ -451,7 +459,6 @@ bool UVAAbstractSourceComponent::SetOffsetRotation(const FRotator Rot) } - // ****************************************************************** // // ******* Directivity stuff **************************************** // // ****************************************************************** // @@ -481,9 +488,9 @@ bool UVAAbstractSourceComponent::SetDirectivityByFileName(const FString FileName if (FileName == "") { - return SoundSource->RemoveDirectivity(); + return SoundSource->RemoveDirectivity(); } - + return SoundSource->SetDirectivity(CurrentReceiverActor->GetDirectivityByFileName(FileName)); } @@ -516,7 +523,6 @@ FString UVAAbstractSourceComponent::GetDirectivityFileName() const } - // ****************************************************************** // // ******* Graphical Representation ********************************* // // ****************************************************************** // @@ -568,8 +574,8 @@ bool UVAAbstractSourceComponent::SetBoneName(const FString NewBoneName) { BoneName = NewBoneName; MovementSetting = EMovement::AttachToBone; - FVAUtils::LogStuff("[UVASourceComponent::SetBoneName()]: Successfully found bone with name" + - BoneName + "and set Movement Setting to follow the bone", false); + FVAUtils::LogStuff("[UVASourceComponent::SetBoneName()]: Successfully found bone with name" + + BoneName + "and set Movement Setting to follow the bone", false); return true; } FVAUtils::OpenMessageBox( @@ -584,7 +590,7 @@ FString UVAAbstractSourceComponent::GetBoneName() const FVAUtils::LogStuff("[UVASourceComponent::GetBoneName()]: Movement is not set to AttachToBone..", true); return "SoundSource is not attached to bone, but current bone is: " + BoneName; } - + return BoneName; }