Trouble casting to Tasks

Hi! I have been working in Unreal Engine for a while and for the life of me can’t figure out casting. I am trying to cast to a task from a ui piece, and I genuinely cannot figure out what the object reference should be. I’m absolutely stumped. I don’t know what other information is needed to be honest, all I need is for the casting to work. I can’t tell if I’m just really dumb, or if this won’t work. thanks!

What do you mean by ‘task’? Do you mean to call a custom event in another widget? ( It looks like you want to access variables ). Then all you in fact need is a reference of the correct type, to that widget. Reference are returned when you create widgets.

Looking at what you have here, it seems you’ve falling into the well known trap that a lot of other people have, namely that because this node is called ‘cast’, there’s some idea that it will get the reference for you. A bit like casting a line out for a fish.

In fact, the cast node could be better named ‘GetRelated’ perhaps? Using the fish example, you could cast from Fish to Trout, because a Trout is an example of a Fish. But you need the Fish to start with.

If you’ve coded a widget called MyWidget, and you have a variable of type ‘WidgetBlueprint’, then you can cast from the widget blueprint to your MyWidget. Casting takes you down the inheritance tree, MyWidget inherits from WidgetBlueprint. But if you use a variable of type MyWidget, you don’t need to cast at all, because the variable is already of the correct type.

1 Like

thank you, I mean blueprint tasks coming off of a behavior tree. I ended up finding a work-around by putting the script inside the task, instead of trying to cast to the task from another widget.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.