Help: Using a Trigger Volume to play audio on DefaultPawn

I am trying to play a sound when the player walks through a trigger volume, but it’s not quite working out.

Here’s what I’ve done:

  1. Added an Audio Component to my DefaultPawn (I’d like the audio to sound like it is coming from the players own mind). It’s declared, with a nullptr assigned in the .h file. In the .cpp file I have protected using an if function.

  2. Added a Trigger Volume to my scene.

  3. Declared it in the .h file.

#include "Engine/TriggerVolume.h"

UPROPERTY(EditAnywhere)
ATriggerVolume* TriggerWelcome;

  1. When I click on the desired Trigger Volume in the DefaultPawn edit menu, it doesn’t populate the dropdown menu. It just stays as “None” (It does allow me to select the trigger volume when playing the game, via ejecting and repossessing).

My questions:

  • Why does it not allow me to select the trigger volume?
  • Is there a better way to be doing this?

Thanks,

  1. Because the blueprint class doesn’t exist in the world, it can’t refer to things that do. You can only set that on instances of the blueprint.

  2. Yes but it’s not taught yet. I would make an actor or a component to attach to a trigger volume that would then use the multicast delegate OnActorBeginOverlap that’s on the actor.

    OnActorBeginOverlap has the signature void(AActor*, AActor*) so you would write a function
    .h:

    UFUNCTION()
    void OnTriggerOverlap(AActor* OverlappedActor, AActor* OtherActor);
    

    .cpp:

    void AMyTriggerActor::BeginPlay()
    {
        OnActorBeginOverlap.AddDynamic(this, AMyTriggerActor::OnTriggerOverlap);
    }
    void AMyTriggerActor::OnTriggerOverlap(AActor* OverlappedActor, AActor* OtherActor)
    {
        // do stuff
    }
    

    Then that would call OnTriggerOverlap when something overlaps it.

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

Privacy & Terms