Spawn component from a component

Hello.

Here are some questions that might help you to find solution to problem.

Are you sure that your actor doesn’t hide your widget inside of it?(little posibility but still)

Have you checked if it is rotated towards you? Since you’re spawning it and not setting the space, it’s safe to assume it’s set to “world”, so you’ll only be able to see it if it’s rotated towards you.

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

When I check in the details panel in the actor that contains the audio component, I don’t see a widget component being spawned.
I have checked all angles and even at world origin in case it’s spawned there, but it’s not

Sorry i didn’t answer for so long did you solved your problem?
If not maybe consider logging this components world position so you can be sure where it is.

Not yet, I’m currently on holiday so I’ll take a look at it when I get back, thanks for the help