Play SoundCue in Editor code from a FAdvancedPreviewScene

I faced this problem a couple of months ago for the first time but i decided to skip it and develop other features of my plugin. One of these features exposes, to the editor, a custom scene derived from FAdvancedPreviewScene class, it allows game designers to provide a preview of what was the result of pressing some inputs and changing values in the Slate Widgets, then a routine serializes and saves these changes into a binary file for later use, nothing special but what i’m trying to achieve now is to play a SoundCue at the position of a SkeletalMeshComponent in this scene. This SkeletalMeshComponent has an AudioComponent attached to it. The sound should be emitted by the AudioComponent at the certain location in the world making use of attenuation settings (in order to obtain the desired positional effect) set in the soundcue loaded. This problem appears to be bound only with the editor code, maybe for some obvious reasons, that i didn’t find at the moment.
I hope someone can help me. Thanks in advance.

The code looks something like this:


	USoundWave * SoundWave = LoadObject<USoundWave>(
	    NULL, TEXT("SoundWave'/Plugin/Sounds/Full_Wave.Full_Wave'"),
	    NULL, LOAD_None, NULL);
    //...
    USoundCue* SoundCue = LoadObject<USoundCue>(
		NULL, TEXT("SoundCue'/Plugin/Sounds/Full_Cue.Full_Cue'"),
		NULL, LOAD_None, NULL);
	AudioComponent->SetSound(SoundCue);
	AudioComponent->SetWaveParameter(FName(TEXT("InWaveParam")), SoundWave);
	AudioComponent->Play();

参考一下EditorEngine.cpp中的:

UAudioComponent* UEditorEngine::PlayPreviewSound(USoundBase* Sound, USoundNode* SoundNode)
{
if(UAudioComponent* AudioComponent = ResetPreviewAudioComponent(Sound, SoundNode))
{
AudioComponent->bAutoDestroy = false;
AudioComponent->bIsUISound = true;
AudioComponent->bAllowSpatialization = false;
AudioComponent->bReverb = false;
AudioComponent->bCenterChannelOnly = false;
AudioComponent->bIsPreviewSound = true;
AudioComponent->Play();

	return AudioComponent;
}

return nullptr;

}
将你插件中的声音组件修改上述变量即可

补充一下,你需要在继承的FEditorViewportClient中修改GetWorld()->bAllowAudioPlayback=true;
不然还是不能够播放