GEngine::GetMainAudioDevice() returns a FAudioDeviceHandle struct, not a FAudioDevice pointer. You should be able to access the underlying FAudioDevice* with FAudioDeviceHandle::GetAudioDevice()
Keep in mind that some engine resources may not be available on Dedicated Servers, Audio Devices among them. This post may be able to help you if this is the case.
Thank you for sharing the link and for the assistance. I’m considering a single-player game at this moment. I’ll check both solutions and let you guys know if that works.
The error message is:
Exception thrown at 0x00007FFEC3BA53C0 (UnrealEditor-Engine.dll) in UnrealEditor.exe: 0xC0000005: Access violation reading location 0x00000000000001D8.
Perhaps I need to reference that the user is already in editor or something like that.
Can you please help me with this?
Thanks
The function runs no problem on my end. I’m guessing the error comes from the context in which you are calling the function.
Is it during gameplay
is it being called in the constructor / CDO
is it being called from an editor widget
For the function to work it has to be called after the begin play phase. The world needs to exist for it to “grab it” from the actor context.
Calling it anytime sooner will cause a problem as the GetWorld will fail.
Added some fail-safes to make it compile (it may try to get world during compile run) and pushed the call to postInitializeComponents to play at start if needed (world context is then valid)
Tested with audio playback and it adjusts the volume as expected.
Here is a full dump of the test class I use
header
#pragma once
#include "CoreMinimal.h"
#include "Test.generated.h"
UCLASS()
class CUSTOMIMPORT_API ATest : public AActor
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable)
void DoSomething();
ATest();
UPROPERTY(EditAnywhere,BlueprintReadWrite)
float SoundVolume = 1;
virtual void PostInitializeComponents() override;
};
Thank you so much for your elaborated answer. That helped me to better understand the logic and the code structure. That quoted part fixed the crash, and now the game settings are correct. I’ll close this thread with your solution.