x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.19
Tags:
more ▼

asked Apr 10 '18 at 09:39 AM in C++ Programming

avatar image

dborry
1 1

avatar image Firefly74 Apr 10 '18 at 10:11 AM

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

 #include "Components/WidgetComponent.h"
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

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

more ▼

answered Apr 10 '18 at 11:46 AM

avatar image

dborry
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

This is the USceneComponent's hierarchy:

http://api.unrealengine.com/INT/API/Runtime/Engine/Components/USceneComponent/index.html

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.

more ▼

answered Apr 10 '18 at 10:53 AM

avatar image

Velrin
375 2 10 13

avatar image Firefly74 Apr 10 '18 at 11:57 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Apr 10 '18 at 11:46 AM

avatar image

dborry
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question