Download

UE4.26 Python 3.7 functions as blueprint nodes: what are the values for "ret"?

UE4.26.1
Python 3.7.7
Python API Documentation

I’m exposing Python functions as blueprint nodes with:

unreal.ufunction(meta=None, ret=None, params=None, override=None, static=None, pure=None, getter=None, setter=None)

For instance :

@unreal.ufunction(ret=str, static=True, meta=dict(Category=“Python Methods”))
def PythonVersionNumber():
return str(sys.version_info.major) + “.” + str(sys.version_info.minor)

PythonVersionNumber.png

which correctly returns ‘3.7’ as a string which can be reused by further blueprint nodes.

However, the UE4 Python API documentation does not enumerate the various “ret” types; bool, int, and str were obvious, but…

…for instance, what if I want to “ret” an “unreal.Array(int)”, or to “ret” a Python list?

Also, it’d be great to be able to give meaningful (blueprint) names to both input and output parameters, instead of “Returned value”; how I can achieve this?

Thanks in advance!

Hey, I checked in with the dev team on this question. They highly recommend using the built-in Execute Python Script node to call your Python code:

Exposing your own functions from Python to BP is likely to end up with you seeing a lot of errors down the line.

Having said that, to answer your questions:

  • Yes, ret can take all kinds of types. There’s built-in data marshalling for simple Python types like int and bool, as you’ve discovered, to convert them to types Unreal can work with. I believe that should work for Python collections like the list as well, though ones that don’t have direct Unreal equivalents like tuples will likely get mapped to the closest fit. Unreal types like unreal.StaticMeshActor should also work.
  • To name your input parameters, you just have to name them in the def statement. Like this:

     @unreal.ufunction(params=[str, str], ret=str, static=True, meta=dict(Category="Python Methods"))
    def PythonVersionNumber(myFirstParamName, mySecondParamName):
        return str(sys.version_info.major) + "." + str(sys.version_info.minor)


node.png

I do not believe there’s a way to rename the return value, though.