Cast to UWidgetComponent?

Hi everyone,

Maybe I’m missing something obvious, but this simple line won’t even compile on my project:

UWidgetComponent* widget = Cast<UWidgetComponent>(SceneRoot);

Where SceneRoot is of type USceneComponent.
Does anyone know why it can’t build ? I’m just trying to access one or several widgets components of my blueprint.

What is the output log for the compilation ?
i assume you have the correct include :

#include "Components/WidgetComponent.h"

USceneComponent do not inherit from UWidgetComponent which would be the reason for the cast failing.

This is the USceneComponent’s hierarchy:

What is it you’re trying to accomplish? Are you just using the SceneRoot to access some of its children? Perhaps you can call…

TArray Components;
SceneRoot->GetChildrenComponents(true, Components);

Then cast the UWidgetComponent from that list that you’re trying to access.

well UWidgetComponent inherit from USceneComponent ^^
But looks like it was as missing UMG module

Thanks for the answers, I found the solution.
It turns out I did miss something obvious, I forgot to include the UMG module in the build.cs file.
Sorry for the unecessary post, I’m still very new to UE4

Thanks for the answers, I found the solution.
It turns out I did miss something obvious, I forgot to include the UMG module in the build.cs file.
Sorry for the unecessary post, I’m still very new to UE4