FApp::GetDeltaTime returns big time after UGameplayStatics::OpenLevel

Hello!
I have a class ADefaultGameMode : public AGameModeBase, and it have a member
UPROPERTY() class UAudioComponent* audioMusicMenu;

I want to cross fade music from main menu to music of level just after it opened ising UGameplayStatics::OpenLevel(this, name);

The code is simple - in ADefaultGameMode::StartPlay:
audioMusicMenu->FadeIn(2.0f);

UAudioComponent uses FApp::GetDeltaTime for fading timers, but after level is opened, in first tick FApp::GetDeltaTime returns a very big time period, if level is large and it’s loading took many time
(it looks like exactly the time of loading level). So volume of music instantly reaches target volume without any fade
(in void FActiveSound::UpdateWaveInstances(TArray &InWaveInstances, const float DeltaTime)
PlaybackTime += DeltaTime and this is a very big time in this case).

Is it a buf or feature?
Where I have to start fading of music for correct result?

Hey Andrey_t-

What is the value of DeltaTime you’re seeing after OpenLevel is called? When testing locally, the returned value is usually between ~0.07 - ~0.2. If possible, can you provide a sample setup or reproduction steps to help me reproduce the behavior you’re seeing on my end?

Here https://cloud.mail.ru/public/BBeY/HmFt1x6ag is the prtoject based on standart Vehicle C++ Project. Starting from map VehicleAdvExampleMap press key “O” - will be called code:
void ABugReportPawn::OnOpenLevel()
{
UGameplayStatics::OpenLevel(this, “VehicleAdvExampleMap2”);
}
In the map VehicleAdvExampleMap2 I duplicated some meshes and landscapes to enlarge size and time of loading. Also a put AMyActor in this scene with this code:
// Called every frame
void AMyActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
UE_LOG(LogTemp, Warning, TEXT("%f"), FApp::GetDeltaTime());
}

And now we see in log:

LogLoad: Took 1.258420 seconds to LoadMap(/Game/VehicleAdvCPP/Maps/VehicleAdvExampleMap2)
LogTemp:Warning: 0.008333
LogTemp:Warning: 1.292989
LogTemp:Warning: 0.061452
LogTemp:Warning: 0.010874
LogTemp:Warning: 0.008333

Second tick will grow if we enlarge loading map size. And this tick is a big problem for fading audio.

Hey Andrey_t-

The DeltaTime that you’re seeing is the first time the game was able to tick after the load process completed. The game does not actually tick during loading so when loading is done and it is able to tick again, the result that you’re seeing is the difference between the last tick before loading started and the first tick after loading completed. The larger a level is, the larger this DeltaTime will be because of how long it takes it to load the level. This appears to be working as intended to me.

You mentioned trying to fade in your sound when your new level loads. If you’re having an issue with your sound I would suggest creating a new post and include how you’re setting up and calling your audio / fade in.

Cheers

Like I said, in ADefaultGameMode::StartPlay: audioMusicMenu->FadeIn(2.0f);
And it will not be faded correctly with 100% guarantee - because if level loading took more then 2 seconds, then after 2 first ticks fading will be finished - it uses GetDeltaTime for timers in ActiveSound.cpp. So what I am doing now - I waiting for 5 ticks (for sure) and then start fading - and it’s working fine. But it is not a good decision.

How are you initializing audioMusicMenu? Are you giving it a value in code or are you setting it in the editor? What type of file are you using as your sound? The sample project you provided does not appear to setup a sound component in the gamemode class, can you provide the full code for how you’re setting up / using your sound?

Additionally, rather than defining your audio component in your game mode class, are you able to define it in another class such as your MyActor class and call it on BeginPlay rather than StartPlay?

Play only in Standalone Game mode. I have audioMusicLevel in UMyGameInstance. I use this music for fading in when level loaded and fading out when level done and we going to Main Menu through loading screen, so it’s global and it have no UWorld when created.

Now run game in Standalone Game mode and press “O” - scene opened, music is playing, but no fading.

You may comment " if (ready) " in ABugReportGameMode::StartPlay() - then music will start with first scene loading (just when game started) - and fading is Ok.

Thank you for the sample project. I encountered the behavior you mentioned (fade in not playing) when using the SND_Music file however, when I replaced the reference to this file in MyGameInstance.cpp with another sound file from the StarterContent/Audio folder, the fade in does play as expected.

Since we cannot reproduce this using any of our starter content with your setup, it seems the problem is likely due to the sound asset in particular. I also noticed that the duration of the SND_Music file had a decimal, try truncating the duration to an clean non-decimal number.

I think this is because after the first run the following occur much faster (due to caching apparently). If you reboot the system and run the game even with music from StarterContent (Starter_Music01 for example) - a bug is still there.

I tested again using your suggestion and was able to hear the fade in. As you mentioned previously, increasing the FadeInDuration will make the fade more prominent / distinguishable. Additionally, since this is specific to when switching levels, you can put the fade in behind a ULevelStreaming::IsLevelLoaded() call. This will ensure that the level has been fully loaded before attempting to start the fade in.

Thank you very much, . For your patience.