x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Adding the file location of a sound to a Sound Base?

How do I attach the address/file location of a sound file directly to a Sound Base?

Right now, I have a declaration of a Sound Base object with a UPROPERTY EditAnywhere tag in my .h file and then the call the sound effect in my .cpp file.

.h snippet:

 // The sound effect for failing a teleport action.
 UPROPERTY(EditAnywhere, Category = "Ability Settings")
 class USoundBase* FailureSound;

.cpp snippet:

 // Plays a buzzer at UI level when called.
 void UShooterAbility::PlayFailureSound()
 {
     if (FailureSound != NULL)
     {
         UGameplayStatics::PlaySound2D(this, FailureSound, 1.f, 1.f, 0.f, nullptr, GetOwner());
     }
 }

It works! -- after I launch the game and add the sound effect to the component file. When I stop the game, the file is no longer associated and I have to re-assign it every time.

How do I hard code this location? I'm not seeing anything in the documentation.

I found a post that recommended I add an additional Sound Cue object and link it:

 // Called when the game starts
 void UShooterAbility::BeginPlay()
 {
     Super::BeginPlay();
     static ConstructorHelpers::FObjectFinder<USoundCue> MySoundFile(TEXT("/ShooterGame/Content/Sounds/InterfaceAudio/Stereo/MenuExitStereo_Cue"));
     FailureSound = MySoundFile.Object;
 }

This crashes the editor on execution.

Thoughts?

Product Version: UE 4.20
Tags:
more ▼

asked Dec 02 '18 at 08:43 PM in C++ Programming

avatar image

mrussell1986
3 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

If you would look in to the logs (Saved/Logs in project directory) you would get immediate answer ;] ConstructorHelpers functions as name suggests work only in class constructor and this is where you should do this, otherwise it will crash the engine and it should inform you that this should not be used in elsewhere in constructor inside the logs. It needs to be in constructor in order to hard code default asset in to CDO without need for pointed asset to be loaded.

The runtime code errors (at least once that engine is programmed to detect) either prints out errors in log or crash engine (via assetion system https://en.wikipedia.org/wiki/Assertion_(software_development)) and prints out failed condition, sometimes with full error message sometimes also hinting solution. So every time you have crash, your first action should be checking log, it will save you a lot of time.

more ▼

answered Dec 02 '18 at 09:25 PM

avatar image

Shadowriver
37.3k 936 172 1116

avatar image mrussell1986 Dec 02 '18 at 11:04 PM

Awesome, thanks! But that still didn't fix my file directory issue.

Wound up playing around with it for another couple of hours. Here's the result:

1) Moved the assignment code to the constructor, per Shadowriver's comment.

2) Used the filepath from the mouse-over tooltip in Unreal instead of the Windows Explorer filepath.

 // Sets default values for this component's properties
 UShooterTeleportAbility::UShooterTeleportAbility()
 {
     // Set this component to be initialized when the game starts, and to be ticked every frame.
     PrimaryComponentTick.bCanEverTick = true;
 
     static ConstructorHelpers::FObjectFinder<USoundCue> AbilitySoundFile(TEXT("/Game/Sounds/InterfaceAudio/Stereo/MenuExitStereo_Cue"));
     AbilitySound= AbilitySoundFile.Object;
 }

Working great!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question