BluePrint function with downcast return nil

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

&aka("getWidgetTestBP")
(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?

bluePrint:

button3Actor ! (constructor)

() 
  [
     branch [_downcastTest]
  ]

button3Actor.getWidgetTestSK()

() Buttons3 
  [
    widget_component.user_widget_object<>Buttons3
  ]

button3Actor._downcastTest:

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

I believe your getWidgetTestSK should be:

@widget_buttons_3.user_widget_object<>Buttons3

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.

https://monosnap.com/file/HSi3zHFCJz0Ue3I1k1kbN6stUHNX7c

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

https://monosnap.com/file/JUeSLg2a3nC69as7DAuLBkchTSNfxK

Instead of checking nil?, try checking valid?:
widget_test_bp().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.
https://monosnap.com/file/nFVd8n2bVUylz3I35GivkqhsHllT4J

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:

test_widget_bp()<>TestWidget.test_function()

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
[
   my_widget.test_function
]

You can also do this without calling through to the BP:
@test_widget.user_widget_object<>TestWidget.test_function

Or ideally, a little more carefully:

!widget : @test_widget.user_widget_object
    
if widget.valid? and widget.class_of?(TestWidget)
[
  widget<>TestWidget.test_function
]

It works! Thanks for help and advice

1 Like