Call a blueprint class function from Python

It is possible to set variables of blueprint classes from Python as shown here: Can you edit a Blueprint Variable from Python? - Editor Scripting - Unreal Engine Forums. However, it is possible to call a function that is marked as “Call in Editor”?

My specific use case is to spawn and configure a blueprint class in a level in the editor.

Once you have a reference to your Blueprint you can call one of his functions by using the method call_method(...)

Methods inherited from _ObjectBase:

call_method(…)
x.call_method(name, args=tuple(), kwargs=dict()) → object – call a method on this object via Unreal reflection using the given ordered (tuple) or named (dict) argument data - allows calling methods that don’t have Python glue

https://docs.unrealengine.com/4.26/en-US/PythonAPI/class/_ObjectBase.html#unreal._ObjectBase.call_method

your_ref.call_method("YourFunctionName")

2 Likes

if inside function exist local variables it’s work wierd!
actor.call_method("Test")
It always need arguments for all local variables
actor.call_method("Test", kwargs={local_var_int': 0})

But after it ask arguments for all nodes than uses local variable!
I just print this int local variable and get this

LogPython: Error: TypeError: test() required argument 'call_func_conv_int_to_string_return_value' (pos 2) not found

But you can create new function without local variables and inside it call old function with local variables. And it work perfect!

1 Like

Hello!

For future reference, here is a more complete example of how to do this, because it is not that trivial to find out exactly what to do:
Call functions or modify properties of a Blueprint from Python | Epic Developer Community (epicgames.com)