Can i get some help

i wrote the exact code that was typed in video but for some reason there is no sound at all
and here is a piece of code to insure :
void UOpenDoor::OpenDoor(float DeltaTime)

{

CurrentOpenYaw =FMath::Lerp(CurrentOpenYaw, TargetOpenYaw, DeltaTime * DoorOpenSpeed);

FRotator DoorRotation = GetOwner()->GetActorRotation();

DoorRotation.Yaw = CurrentOpenYaw;

GetOwner()->SetActorRotation(DoorRotation);

CloseDoorSound = false;

if(!AudioComponent){return;}

if (!OpenDoorSound)

{

    AudioComponent->Play();

    OpenDoorSound = true;   

}

}

void UOpenDoor::CloseDoor(float DeltaTime)

{

CurrentOpenYaw =FMath::Lerp(CurrentOpenYaw, InitialOpenYaw, DeltaTime * DoorCloseSpeed);

FRotator DoorRotation = GetOwner()->GetActorRotation();

DoorRotation.Yaw = CurrentOpenYaw;

GetOwner()->SetActorRotation(DoorRotation);

OpenDoorSound = false;

if(!AudioComponent){return;}

if(!CloseDoorSound)

{

    AudioComponent->Play();

    CloseDoorSound = true;

}

}

Did you verify that you added the sound effect to the actual audio component on the unreal editor?

And that an audio component is attached.

I’m facing the same issue, in fact, I found out that when I call

void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialYaw;
	OpenAngle += InitialYaw;

	FindPressurePlate();
	FindAudioComponent();	
}

I have got AudioComponent pointing on 2 doors, but when I call

void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	

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

AudioComponent is nullptr
How can I fix it? I’ve followed all the steps in this lecture but without any success

Is that for the same component instance?

I’m having the same issue. When I assign the UAudioComponent to my AudioComponent variable, it detects it, but as soon as I go to play the file, AudioComponent is back to pointing to null.

I’m in a similar boat.
I have followed the video a few times to see where I might have gone wrong but my syntax matches and there’s no compile errors. My issue is that the sound affect doesn’t play when my door opens or closes.
I know it is attached to the component properly because it does play when I tick Auto Activate. No other time. Not sure which piece of code to show for reference at this point.

Could you post some snippets of your methods?
So, BeginPlay, CloseDoor, OpenDoor, FindAudioComponent, and TickComponent, please and thanks.

This happened to me. I forgot to call FindAudioComponent(); at BeginPlay.

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

Privacy & Terms