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"

Preventing AudioComponent from being destroyed

Hello there!

Going straight to the problem. I'm trying to create UAudioComponent that can be paused and hold into memory until I decide to delete it. Now i have problem with it becouse after some time on level my sound just disappears.

This is how I'm creating it right now:

 UAudioComponent* UAudioController::Sound2D(UObject* WorldContextObject, class USoundBase* Sound, float VolumeMultiplier, float PitchMultiplier, float StartTime)
 {
     if (!Sound)
     {
         return nullptr;
     }
 
     UAudioComponent* AudioComponent = UGameplayStatics::CreateSound2D(WorldContextObject, Sound, VolumeMultiplier, PitchMultiplier, StartTime);
     PlaybackPositionMap.Add(AudioComponent, 0.f);
     BindDelegates(AudioComponent);
     AudioComponent->Play(StartTime);
     return AudioComponent;
 }

PlaybackPositionMap is just TMap that holds reference to UAudioComponent and float that is time played from that sound.

BindDelegates function looks like this:

 void UAudioController::BindDelegates(UAudioComponent* AudioComponent)
 {
     if (AudioComponent->IsValidLowLevel())
     {
         AudioComponent->OnAudioPlaybackPercent.AddDynamic(this, &UAudioController::SavePlaybackPosition);
         AudioComponent->OnAudioFinished.AddDynamic(this, &UAudioController::SoundFinished);
     }
 }

I do not think you need it but just to be clear with it. I tried saving reference to UAudioComponent in arrays maps static components and disallowing it's destruction but it always dissapears. Any way I can change that?

Product Version: UE 4.17
Tags:
more ▼

asked May 29 '18 at 02:49 PM in C++ Programming

avatar image

Avengar
13 3 5 7

(comments are locked)
10|2000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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