Download

Problems creating UModularSynthComponent in C++

So, I’m using the new Audio Engine with the Synthesis plugin and I can use it with Blueprint just fine, but there are just some things you can’t do with Blueprints. I want to create a UModularSynthComponent in a C++ constructor and attach it to an Actor, but when I compile the Blueprint class derived from this C++ class the editor crashes. Based on the crash report it looks like the code is failing this check, which gets called during the CreateAudioDevice function:


void USynthSound::StartOnAudioDevice(FAudioDevice* InAudioDevice)
{
    check(InAudioDevice != nullptr);
    bAudioMixer = InAudioDevice->IsAudioMixerEnabled();
}

Here’s my declaration of the synth component:


UPROPERTY(EditAnywhere, BlueprintReadOnly)
        UModularSynthComponent* ModularSynth;

And the constructor I’m trying to spawn the component in:


AEffectsRack::AEffectsRack(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
    PrimaryActorTick.bCanEverTick = true;

    StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(FName("Root"));
    RootComponent = StaticMesh;

    ModularSynth = CreateDefaultSubobject<UModularSynthComponent>(FName("Modular Synth"));
    ModularSynth->SetupAttachment(RootComponent);
}

So, what did I miss? Do I need to initialize the synth component in the constructor? Why isn’t there an UAudioDevice being created?

I figured it out. If I do NewObject<UModularSynthComponent> at BeingPlay instead of in the constructor, it doesn’t crash. The component doesn’t show up in the hierarchy that way, but I can still access it by right clicking and getting the variable.