Child Widget Selector ?

After managing to add a a Child Widget to a Canvas I need to set up which child widget to add on creation. I set up a Enum Switch which selects the Class and trying to refine it as a Pure Function, at the moment sets a variable but trying to find a way not to set one ? …

Sorry to bump … Ran into a Casting problem accessing Child Variables. I was casting in the parent widget itself but didn’t need to however still not able to access the variables. So since I know which Cast I need I did it in the blueprint …


For your first issue, you can use the select node to select one class based on an enum. Check this simple blueprint here: This way your function remains pure as it never calls any set nodes. The select node is great when you want to set a value to something different based on a parameter. The parameter can be an enum, bool, int, etc.

Thanks. I should have looked a bit deeper into the select node, more versatile than I thought.

Agreed, good to know, cheers @dminiatoibi .

Makes me wonder how many other nodes I’ve overlooked because the ‘extra flexible’ options were hidden. :wink:
(Its not immediately obvious you need to Right-Click->Add-Option-Pin which breaks BP consistency a bit).

Also, this kind of generic Select makes Select-Class / Select-Object A/B Nodes appear pointless now too.
The only concern as before is here, if these are nested in Tick everything will be evaluated which isn’t good…

Same subject different problem … My second cast “Cast to HomeInfo_Widget” in the CastToWidget Event was actually returning false, I could swear it was casting ok. How can I successfully cast to a child widget ? I should probably say the main widget is a Widget Component inside an actor.

I cant specifically say because I’m not sure exactly how you have it setup, but if the cast is returning false, try putting print strings on the object that you are attempting to cast, and see what it comes out as. Might give you a jumpstart in troubleshooting why the cast has failed.

Not sure what to look for a print out of ? I think returns nothing there. … The images are self explanatory. All variables related I’ve set to editable & expose on spawn just incase.

Print string the display or object name of the Child Widget. Currently what I’m understanding is this: You spawn your widget based on your enumeration, so it is one of 4 possible widget types. The cast will only succeed when it is specifically a HomeInfo_Widget, not a businessInfoWidget. That’s why I’m suggesting the print string after the child widget, so you are able to see exactly what widget it is, and then maybe figure out why the cast isnt working. If it returns a BusinessInfoWidget, then your problem is apparent. :slight_smile:

Still can’t find the problem it just gives nothing in return. I thought it could be because the ChildWidget is a “User Widget Object” which needed to be because it can’t be specific due to the class change but then I figured maybe in the first test the “Create User Widget” was only as “HomeInfo_Widget” class output as “Home Info Widget Object”, so I tried being more specific but still no luck. I any case when I try casting to the widget says no need, even in the Actor with the parent widget says no need to cast. I switched back to a class selection and in the actor using “Cast To User Widget” and this also says no need to cast. In all cases can’t get to the child widget’s variables.

Does anyone have an example of a working relationship of Actor Widget Component using child widgets ?


I’m not really sure why cant access the variables.

I’ve uploaded a very simple photo of it working in my case. You’ll probably need to give an even better description of what it is exactly you are trying to do. What is happening in your Child Widget Select function there?

What did you set for the child widget ?

So my Parent widget class, on event construct, just spawns a Widget of class Child Widget and sets that to the variable of Child widget.

Any chance my project could be corrupt ? … I found a variable that had changed name by itself from var to var_0 claiming I can’t have var because it’s already in use but doesn’t exist anywhere in the same blueprint.

Its possible… There’s a unlikely chance you might be creating a variable that’s already a variable of a parent class? Like if your parent has var, you cant create a var in a child called var, because it already exists. Project corruption is usually the last thing it would be, but it doesn’t mean its impossible.

In your pics looks like you’re creating the widget to known blueprint, if I do this too I can see the variables but a print out shows an error that is was accessing none. Is this the same for you ?

I’ve checked everywhere, the variable doesn’t exist.

Edit: Found the problem, on a linked Interface had a function of the same name. Thought only variables counted.

I mean it all depends on when you access the variable and when you set the variable. If you try to access the variable on begin play, before the widget is constructed, you might not be able to get access to it. In that case, it might make sense to take more control with custom events to determine the order things are happening, rather than relying on even begin play and event construct.

Ok, thanks for the help. :slight_smile: