[Solved] BluePrint function with downcast return nil

hi. I made a function in blueprint with downcast and return
this function in sk:

(Buttons3 button_3 : Buttons3!null)

The problem: in sk I got nil
What could be the problem?
I’m tried to write this same function in sk and downcast works well.

Can you post a screenshot of your blueprint and any code involved?


button3Actor ! (constructor)

     branch [_downcastTest]


() Buttons3 


    println("get from sk: ", getWidgetTestSK().nil?)
    println("get from bp: ", widget_test_bp().nil?)

I believe your getWidgetTestSK should be:


Your right. It can be @widget_button3 but this function works well in your and my variant. I have a problem with function declared in bp - widget_test_bp(). Is downcast inside bp can’t work?

Are you sure the BP cast is successful? There’s a chance the cast does not work.


What does :sk: show as the function prototype for widget_test_bp? I can almost see it here:


Instead of checking nil?, try checking valid?:

valid - return true, but I can’t call blueprint functions.

getWidgetTestSK().show_button_text() //this call work 
widget_test_bp()<>Buttons3.show_button_text() //this call doesn't work

Does the function exist? Go to Buttons3 class in :sk: ide and see if it is listed and what functions it has.

Yes it exist. sk downcast call bp function like expected but downcast from bp can’t call.

Please attach images directly to the forum, otherwise it is more difficult for me to understand all of your code.

Can you share a sample project? I don’t fully understand what you are trying to do from the data given. Are you sure the world and player and UI exist before you call any of this? Constructors can be called internally before the world is up, so you should avoid firing off any logic from the constructor unless it is a listener.

If you have a time to look it will be nice)
project example

Ok, thanks for sharing, I see the problem.

Sometimes BP generated functions aren’t what you expect. Take a close look at the function parameter:

(TestWidget widget : TestWidget!null)

You need to pass in the parameter object to write to. So instead of this:


Do this:

!my_widget : TestWidget!null // create null return parameter
test_widget_bp(my_widget) // pass parameter into function
if my_widget.valid? // make sure it is valid

You can also do this without calling through to the BP:

Or ideally, a little more carefully:

!widget : @test_widget.user_widget_object
if widget.valid? and widget.class_of?(TestWidget)

It works! Thanks for help and advice

1 Like