Audio plays even when my code does not authorize it

The audio always plays whenver i click play. I’ve searched my code to ensure that i haven’t called

AudioComponent -> Play()

anywhere. I’ve tried to find other people with similar problems under the ask section of this community, the solution that seemed to come up was to disable auto activation, but i’ve done that, it’s still plays the sound when i click play and also when DefaultPawn_BP enters the trigger volume the first time, but doesn’t play when DefaultPawn_BP enters the trigger volume again

Could you post your code and screenshot of the auto activates on your components on all doors you may have them on?

 // Fill out your copyright notice in the Description page of Project Settings.
#include "Components/AudioComponent.h"
#include "Components/PrimitiveComponent.h"
#include "Engine/World.h"
#include "GameFramework/Actor.h"
#include "Math/UnrealMathUtility.h"
#include "OpenDoor.h"

// Sets default values for this component's properties
UOpenDoor::UOpenDoor()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    PrimaryComponentTick.bCanEverTick = true;
    // ...
}

// Called when the game starts
void UOpenDoor::BeginPlay()
{
    Super::BeginPlay();
    InitialYaw = GetOwner()->GetActorRotation().Yaw;
    FindAudioComponent();
}

// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
    if (TotalMassOfActors() >= MassToOpenDoor)
    {

        OpenDoor(DeltaTime);
        DoorLastOpened = GetWorld()->GetTimeSeconds();
    }
    else
    {   if(PressurePlate)
        {
            if (GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorCloseDelay)
            {

                CloseDoor(DeltaTime);
            }
        }
    }
}

void UOpenDoor::OpenDoor(float DeltaTime)
{
    DoorRotation = GetOwner()->GetActorRotation();
    DoorRotation.Yaw = FMath::Lerp(DoorRotation.Yaw, TargetYaw, DeltaTime* 0.5f);
    GetOwner()->SetActorRotation(DoorRotation);
}

void UOpenDoor::CloseDoor(float DeltaTime)
{
    DoorRotation = GetOwner()->GetActorRotation();
    DoorRotation.Yaw = FMath::Lerp(DoorRotation.Yaw, InitialYaw, DeltaTime* 1.5f);
    GetOwner()->SetActorRotation(DoorRotation);
}

float UOpenDoor::TotalMassOfActors()
{
    float TotalMass = 0.f;
    TArray<AActor*> OverlappingActors;
    PressurePlate->GetOverlappingActors(OverlappingActors);

    for (AActor* Actor : OverlappingActors)
    {
        TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->GetMass();

        UE_LOG(LogTemp, Warning, TEXT("%s is overlapping"), *Actor->GetName())
    }
        return TotalMass;
}

void UOpenDoor::FindAudioComponent()
{
    AudioComponent = GetOwner()->FindComponentByClass<UAudioComponent>();
    if(!AudioComponent)
    {
        UE_LOG(LogTemp, Error, TEXT("%s missing audio component"), *GetOwner()->GetName())
    }
}

autoactivate

You don’t use the audio component anywhere in your code and are you sure that you only have one open door component in your level?

Yes its just one open door component. I dont know if this matters, but the sound does not play continously, it plays just once. In the tutorial it kept on looping until he used an if loop to check if sound has been played.

Because you don’t call Play anywhere in your code so the only logical place it would happen is the auto activate and then no where else. I’d suggest removing the component and re-adding it.

I just found out that my auto save was off. Thank you, its now working

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms