Cast failing when it should not

Please check this screenshot:

This results in “Cast Failed”. But, as you can see, I am trying to cast to VerticalBoxSlot and it is a VerticalBoxSlot.

Anyone knows why is this failing?

Nope. Sorry, I see now that the name of the variable can cause this confusion, but the blueprint is correct: these “Container” variable is also child of another widget, and I actually want to get it’s slot.

But none of that matter: if you see the white box, it’s showing the current value of the slot while I was debugging. It shows a VerticalBoxSlot. So why the cast is failing?

Hello Marcio Daniel!

You have to get the slot of the child, not the container.

DId you ever figure this out? I am having the same issue. Casting to a slot that it apparently is, is failing.

Sorry, but no, I didn’t. I had to change the approach to get the result I wanted because I never figured out how to solve this.

How did you create “container” and “slot” widgets : by adding directly on widget editor or calling CreateWidget and promote to reference ? The failure possibly comes from validity even if it seems to have a value (if you added directly on widget editor).

@CinnamonSouls post screen shots of your set up. This shouldn’t be hard to figure out. I would comment on the original screen shot but I need more info before I can really tell what the issue is. “Container” and is what type of variable exactly? How is it setup in the widget hierarchy etc. So instead of trying to fix an old issue, post your current issue along with a general “goal” of what you are trying to accomplish and we will go from there.

Below are my screenshots. I have the Text Size Box as a child of the overlay. You can see that it’s a variable and a valid overlay slot. You can see where I cast it to overlay slot and set padding. You can also see where I test to see if the variable is even valid. According to the logs, it’s not!

271706-screen-shot-2019-03-18-at-50736-pm.png

You are getting the wrong slot and you don’t need to cast. Just tested this out and it works fine. As for the “Is Valid”, did you add your widget to the viewport?

I was running my init script before adding to the viewport, I didn’t realize things weren’t valid until adding as a child or whatnot, I thought constructing was enough. Thank you so much! You have saved me a lot of time.

No problem. Glad to help.