UE--如何用 Python 调用 C++ 及蓝图函数

前言

先讲下如何用 Python 调用 C++ 函数吧。
详细可见我的上篇文章

最关键的一点就是得在函数上加一个宏:UFUNCTION(BlueprintCallable)

cpp 复制代码
UFUNCTION(BlueprintCallable)
static bool GetOrCreatePackage(const FString& PackagePath, UPackage*& OutPackage);

然后直接调用就行了

python 复制代码
TestObj.get_or_create_package(...)

主线

那么,如何在 Python 里面调用蓝图呢?

比如我们有一个蓝图TestBP,里面有一个蓝图函数节点:TestFunction,然后有一个参数

python 复制代码
def call_blue_print_function(self):
	blueprint_path = "/Script/Blutility.EditorUtilityWidgetBlueprint'/YourProject/BP/TestBP.TestBP'"
	blueprint_class = ue.EditorAssetLibrary.load_blueprint_class(blueprint_path)
	if blueprint_class:
		utility_instance = ue.new_object(blueprint_class)
		utility_instance.call_method("TestFunction", (some_property, ))

最主要的是:call_method 这个方法。

感兴趣可以直接去看文档
UE Python 官方文档

相关推荐
该用户已不存在5 小时前
Mojo vs Python vs Rust: 2025年搞AI,该学哪个?
后端·python·rust
沐怡旸6 小时前
【底层机制】std::string 解决的痛点?是什么?怎么实现的?怎么正确用?
c++·面试
站大爷IP7 小时前
Java调用Python的5种实用方案:从简单到进阶的全场景解析
python
River4169 小时前
Javer 学 c++(十三):引用篇
c++·后端
感哥12 小时前
C++ std::set
c++
用户83562907805112 小时前
从手动编辑到代码生成:Python 助你高效创建 Word 文档
后端·python
侃侃_天下12 小时前
最终的信号类
开发语言·c++·算法
c8i12 小时前
python中类的基本结构、特殊属性于MRO理解
python
博笙困了13 小时前
AcWing学习——差分
c++·算法
liwulin050613 小时前
【ESP32-CAM】HELLO WORLD
python