References to Python types in Blueprints are not serialized

I have noticed that references in Blueprints to UE types defined in Python are lost on serialization. This affects, function calls, variable and parameter types, etc. When it is a call to a function defined in a Python Blueprint function library class, “UK2Node_CallFunction::AllocateDefaultPins” contains a “fixup” that will try to find the same function name in any available Blueprint function library classes, which most times will work (with a message like “UK2Node_CallFunction: Fixed up function ‘my_function’, originally in ‘(null)’, now in library ‘MyPythonLibraryClass’.”). However, in other cases the Blueprint, which compiles and works when you first set it up, will fail to compile on reload.

I am not sure if it is on purpose or a bug, but it is a bit of a surprising behaviour, especially since it works “as expected” with Blueprint function library classes.

Steps to Reproduce

  1. Create a Blueprint containing a node referencing a UE type defined in Python. For example, a “Cast” node to a Python class decorated with @unreal.uclass
  2. Save and close the Blueprint.
  3. Reload and reopen the Blueprint asset.
  4. The loaded cast node does not have a target type.

Hey there, we don’t support blueprints being saved with references to Python types. See this remark on the docs page Scripting the Unreal Editor with Python:

The aformentioned BPFL method causes issues when an asset is saved or loaded due to Python-generated types being transient, and is no longer officially supported.There is a 3rd party FAB plugin that forces loading of your Python scripts to be sooner during engine startup, which makes them load possibly in time before the BPs that depend on them are loaded, but:

  • There is no guarantee that it’s in time (especially if you have some BPs that are loaded very early, for example by being referenced by Project Settings).
  • We make no effort to support a workflow of BPs referencing Python-defined classes, so the workflow may break at any engine update.

It’s more likely that in the future we prevent saving of blueprints with references to Python-defined classes, rather than adding official support for referencing and loading. I hope this is helpful info to you.