It’s easy if you are using UE5, there is a new editor bp lib: BlueprintEditorLibrary
@classmethod
def compile_blueprint(cls, blueprint):
r"""
X.compile_blueprint(blueprint) -> None
Compiles the given blueprint.
Args:
blueprint (Blueprint): Blueprint to compile
"""
return None
just call it:
unreal.BlueprintEditorLibrary.compile_blueprint(your_bp)
If in UE4, the “compile” function is not callable from python, but you can wrap and make it blueprint callable in your UBlueprintFunctionLibrary, just like BlueprintEditorLibrary.h did
.h
/**
* Compiles the given blueprint.
*
* @param Blueprint Blueprint to compile
*/
UFUNCTION(BlueprintCallable, Category = "Blueprint Upgrade Tools")
static void CompileBlueprint(UBlueprint* Blueprint);
.cpp
void UBlueprintEditorLibrary::CompileBlueprint(UBlueprint* Blueprint)
{
if (Blueprint)
{
// Skip saving this to avoid possible tautologies when saving and allow the user to manually save
EBlueprintCompileOptions Flags = EBlueprintCompileOptions::SkipSave;
FKismetEditorUtilities::CompileBlueprint(Blueprint, Flags);
}
}