# Is it possible to call a blueprint function from python?

**URL:** <https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078>\
**Category:** Blueprint\
**Tags:** unreal-engine, CPP, question, Blueprint\
**Created:** [April 11, 2019, 11:40pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078 "2019-04-11T23:40:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8829be49](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8829be49](https://forums.unrealengine.com/u/anonymous_user_8829be49)\
**Post date:** [April 11, 2019, 11:40pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/1 "2019-04-11T23:40:45Z")

</div>

I found [this answer](https://answers.unrealengine.com/questions/810749/examine-blueprints-functions-with-pythoncpp.html) that explains how to inspect blueprint functions, but I can’t find anything about calling blueprint functions from python. It looks like I would need to pass void\* params from python to c++ in order to pass arbitrary parameters. It looks like I can create a bridge for specific functions, but calling arbitrary functions is impossible. Am I wrong? Is there a way to do this?

This is what I’ve got so far:

```
UFUNCTION(BlueprintCallable)
static void FindBlueprintFunctions(UObject* Asset);

// This doesn't compile. void* Params is obviously not a valid type
UFUNCTION(BlueprintCallable)
void CallBlueprintFunctions(UObject* Asset, FString FunctionName, void* Params)

```

.

```
// This runs, but doesn't return anything yet.
void FindBlueprintFunctions(UObject* Asset)
{
    if (Asset)
    {
        UBlueprint* BlueprintObject = Cast<UBlueprint>(Asset);
        if (BlueprintObject && BlueprintObject->GeneratedClass)
        {
            for (TFieldIterator<UFunction> It(BlueprintObject->GeneratedClass); It; ++It)
            {
                UFunction* Func = *It;

                UE_LOG(LogTemp, Warning, TEXT("Function Name: %s"), *Func->GetName());
                auto& PropertyLink = Func->PropertyLink;
                while (PropertyLink != nullptr)
                {
                    if (PropertyLink && (PropertyLink->GetPropertyFlags() & CPF_ReferenceParm) == 0)
                    {
                        FString ParamName = PropertyLink->GetName();
                        FString ParamType = PropertyLink->GetCPPType(NULL, CPPF_None);
                        UE_LOG(LogTemp, Warning, TEXT(" Parameter: %s - %s"), *ParamName, *ParamType);
                    }
                    PropertyLink = PropertyLink->PropertyLinkNext;
                }
            }
        }
    }
}

UFunction* FindBlueprintFunction(UBlueprint BlueprintObject, FString FunctionName)
{
    if (BlueprintObject && BlueprintObject->GeneratedClass)
    {
        for (TFieldIterator<UFunction> It(BlueprintObject->GeneratedClass); It; ++It)
        {
            UFunction* Func = *It;
            if (Func->GetName() == FunctionName)
            {
                return Func;
            }
        }
    }
    return nullptr;
}

void CallBlueprintFunctions(UObject* Asset, FString FunctionName, void* Params)
{
    if (Asset)
    {
        UBlueprint* BlueprintObject = Cast<UBlueprint>(Asset);
        if (BlueprintObject && BlueprintObject->GeneratedClass)
        {
            UFunction* Function = FindBlueprintFunction(BlueprintObject, FunctionName);
            if (Function)
            {
                BlueprintObject->ProcessEvent(Function, Params);
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0846af92](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0846af92](https://forums.unrealengine.com/u/anonymous_user_0846af92)\
**Post date:** [August 27, 2019, 1:25pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/2 "2019-08-27T13:25:21Z")

</div>

Did you ever find anything for this? I’m now trying to do the same thing in python, but after a very thorough dig through the docs I’ve drawn a blank…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0846af92](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0846af92](https://forums.unrealengine.com/u/anonymous_user_0846af92)\
**Post date:** [August 29, 2019, 2:35pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/3 "2019-08-29T14:35:53Z")

</div>

At this time, python does not have access to blueprint functions, but it **does** have access to your C++ methods.  
So, the solution is to declare your blueprint function in C++ as a `BlueprintImplementableEvent`, and then override it in your blueprint.

I’d recommend checking it works by calling your `BlueprintImplementableEvent` from C++ before you move on.  
Next, make a secondary C++ function to call your `BlueprintImplementableEvent`.  
This function must be implemented as a `BlueprintCallable`, as these are the ones that are exposed to python.

Finally, once your C++ and blueprints are compiled, all you need to do is call your caller function from python;  
your C++ class will be visible as a normal C++ module like so: `unreal.YourClassName.yourCallerFunctionName(yourClassInstance, args)`  
Arguments and return values are handled exactly as you’d expect.  
You must pass your function the class instance you wish the function to run from. Very useful when manipulating specific AActor instances.

* * *

One final note; if you need your function to be implemented as a blueprint **function** rather than a blueprint **event** like I did, you must either make your function constant or give a return value (even if you don’t use it). Otherwise, it will appear in your blueprint overrides as an event.

Screens from my use case, obviously the specifics of my blueprint function implementation is irrelevant:  
**Blueprint function**

 ![Blueprint function implementation of clearSpline(), returning a boolean](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/e/c/0ec46be6c5cab8551a3ad166e231846f303ebac5.png)  
**.h**  
 ![Header file declaring my c++ functions (see image)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/d/3/7d3c1bdfcc8bc9f586e3f222cabb3d1b66e044eb.png)  
**.cpp**  
 ![Implementation of my caller utility function (see image)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/c/e1c1e6c5bd99d545e3c6e6fd16caf825742f180b.png)  
**.py**  
 ![My python code calling the caller function (see image)](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/f/c1fd7d7d2cd2ca3f9ff7a04fd6509d95180f716b.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_0846af92](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_0846af92](https://forums.unrealengine.com/u/anonymous_user_0846af92)\
**Post date:** [August 29, 2019, 2:35pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/4 "2019-08-29T14:35:57Z")

</div>

Error in my **.py** screenshot. The first line should read:  
`if unreal.planeTrackEditableWrapper.call_clear_spline(actor)`  
You may infer from this and my C++ code that planeTrackEditableWrapper is the name of the class containing my blueprint interfacing functions, which is also the parent of my blueprint class.  
Probably should have mentioned the class parenting part as that lets your C++ talk to the blueprint, let me know if you need to hear about that.

---

<div class="post-metadata">

**Author:** ![DW\_MaxR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DW\_MaxR](https://forums.unrealengine.com/u/DW_MaxR)\
**Post date:** [August 31, 2023, 7:53am UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/5 "2023-08-31T07:53:17Z")

</div>

Hello!

Here is a snippet demonstrating how to do that in a simple way, without any C++.  
[Call functions or modify properties of a Blueprint from Python | Epic Developer Community (epicgames.com)](https://dev.epicgames.com/community/snippets/aAlM/unreal-engine-call-functions-or-modify-properties-of-a-blueprint-from-python)

---

<div class="post-metadata">

**Author:** ![Mifthbeat](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mifthbeat/32/919874_2.png) [@Mifthbeat](https://forums.unrealengine.com/u/Mifthbeat)\
**Post date:** [September 3, 2023, 11:16pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-call-a-blueprint-function-from-python/447078/6 "2023-09-03T23:16:38Z")

</div>

You need to do:

- Wrap a function in another function
- Expose inputs in args/kwargs.

In my example I wrapped AddMeshSections function in AddMeshSectionsPy function.  
After that I called this function from Python:

```auto
my_actor.call_method("AddMeshSectionsPy", args=(my_array, ))

```

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/3/9c384edad720e43443f6d59c24a85d784a45d355.png)
