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

Merge branch 'fix/getcomponentbyclass' into 'dev/5.1'

Replace deprecated GetComponentsByClass function

See merge request !10
parents 97513198 50403963
No related branches found
No related tags found
1 merge request!10Replace deprecated GetComponentsByClass function
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment