Hi all, I’m trying to create a custom audio component that displays a 3d widget component for subtitles everytime it plays.
Instead of creating an actor containing the widget and the audio component, I want the audio component to spawn the widget and attach it to itself, that way I can add the components to whatever actor I need.
Here’s my code so far, it doesn’t seem to be spawning the widget
void UAccessibleAudioComponent::PlayAccessibleAudio(float StartTime)
{
Play(StartTime);
//Spawn the accessibility widget
if (true) //Check if subtitles are enabled
{
FVector CompLocation = this->GetComponentLocation();
WidgetComponent = NewObject<UWidgetComponent>(GetOwner(), UWidgetComponent::StaticClass(), TEXT("SubtitleWidget"));
//WidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("SubtitleWidget"));
WidgetComponent->RegisterComponent();
WidgetComponent->AttachToComponent(this, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
WidgetComponent->SetRelativeLocation(FVector(0.f, 0.f, 0.f));
WidgetComponent->SetWidgetClass(UAudioDescriptionUserWidget::StaticClass());
}
}
As you can see I have also tried to use CreateDefaultSubobject, but that is crashing the editor