{"id":1170584,"date":"2025-01-15T16:24:16","date_gmt":"2025-01-15T08:24:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1170584.html"},"modified":"2025-01-15T16:24:19","modified_gmt":"2025-01-15T08:24:19","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8ue%e4%b8%ad%e4%bd%bf%e7%94%a8python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1170584.html","title":{"rendered":"\u5982\u4f55\u5728ue\u4e2d\u4f7f\u7528python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26073146\/be6cc9ab-415f-4a9d-9ac5-15268927842c.webp\" alt=\"\u5982\u4f55\u5728ue\u4e2d\u4f7f\u7528python\" \/><\/p>\n<p><p> \u5728UE\uff08Unreal Engine\uff09\u4e2d\u4f7f\u7528Python\u53ef\u4ee5\u901a\u8fc7<strong>\u542f\u7528Python\u63d2\u4ef6\u3001\u7f16\u5199Python\u811a\u672c\u3001\u4f7f\u7528Python API\u3001\u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177<\/strong>\u6765\u5b9e\u73b0\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u6df1\u5165\u7684\u89c1\u89e3\u548c\u793a\u4f8b\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u542f\u7528Python\u63d2\u4ef6<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728Unreal Engine\u4e2d\u542f\u7528Python\u63d2\u4ef6\u3002<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00Unreal Engine\u7f16\u8f91\u5668\uff0c\u8fdb\u5165\u9879\u76ee\u3002<\/li>\n<li>\u9009\u62e9\u201c\u7f16\u8f91\u201d\u83dc\u5355\uff0c\u7136\u540e\u9009\u62e9\u201c\u63d2\u4ef6\u201d\u3002<\/li>\n<li>\u5728\u63d2\u4ef6\u7a97\u53e3\u4e2d\uff0c\u641c\u7d22\u201cPython\u201d\u3002<\/li>\n<li>\u542f\u7528\u201cPython Editor Script Plugin\u201d\u548c\u201cSequencer Scripting\u201d\u63d2\u4ef6\u3002<\/li>\n<li>\u91cd\u65b0\u542f\u52a8\u7f16\u8f91\u5668\u4ee5\u4f7f\u66f4\u6539\u751f\u6548\u3002<\/li>\n<\/ol>\n<p><p>\u542f\u7528Python\u63d2\u4ef6\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728Unreal Engine\u4e2d\u4f7f\u7528Python\u811a\u672c\u4e86\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728Unreal Engine\u4e2d\u7f16\u5199Python\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u4e2d\u76f4\u63a5\u7f16\u5199\u811a\u672c\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8\u6587\u672c\u7f16\u8f91\u5668\u7f16\u5199\u811a\u672c\uff0c\u7136\u540e\u5728\u7f16\u8f91\u5668\u4e2d\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>1. \u5728\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u811a\u672c<\/h4>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u201c\u7f16\u8f91\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201cPython\u201d\u3002<\/li>\n<li>\u9009\u62e9\u201c\u6253\u5f00Python\u63a7\u5236\u53f0\u201d\u3002<\/li>\n<li>\u5728\u63a7\u5236\u53f0\u4e2d\u8f93\u5165Python\u4ee3\u7801\u5e76\u8fd0\u884c\u3002<\/li>\n<\/ol>\n<p><p>\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u6765\u6253\u5370\u6d88\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>unreal.log(&quot;Hello, Unreal Engine with Python!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u5916\u90e8\u7f16\u8f91\u5668\u7f16\u5199\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5916\u90e8\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982VSCode\u3001PyCharm\uff09\u7f16\u5199Python\u811a\u672c\uff0c\u5e76\u5c06\u811a\u672c\u4fdd\u5b58\u4e3a<code>.py<\/code>\u6587\u4ef6\u3002\u7136\u540e\u5728Unreal Engine\u4e2d\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\u5728\u4f60\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cScripts\u201d\u7684\u6587\u4ef6\u5939\u3002<\/li>\n<li>\u5728\u201cScripts\u201d\u6587\u4ef6\u5939\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201cexample.py\u201d\u7684\u6587\u4ef6\u3002<\/li>\n<li>\u5728\u201cexample.py\u201d\u6587\u4ef6\u4e2d\u7f16\u5199\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>unreal.log(&quot;Hello, Unreal Engine from an external script!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li>\u5728Unreal Engine\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u201cPython\u63a7\u5236\u53f0\u201d\u3002<\/li>\n<li>\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\u8fd0\u884c\u811a\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">unreal.execute_python_script(&quot;Scripts\/example.py&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528Python API<\/h3>\n<\/p>\n<p><p>Unreal Engine\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684Python API\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9bAPI\u6765\u64cd\u4f5c\u5f15\u64ce\u4e2d\u7684\u5404\u79cd\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684API\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>1. \u64cd\u4f5c\u8d44\u4ea7<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Python API\u6765\u64cd\u4f5cUnreal Engine\u4e2d\u7684\u8d44\u4ea7\uff0c\u4f8b\u5982\u5bfc\u5165\u3001\u5bfc\u51fa\u3001\u91cd\u547d\u540d\u8d44\u4ea7\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<h2><strong>\u5bfc\u5165\u8d44\u4ea7<\/strong><\/h2>\n<p>asset_tools = unreal.AssetToolsHelpers.get_asset_tools()<\/p>\n<p>import_task = unreal.AssetImportTask()<\/p>\n<p>import_task.filename = &quot;path\/to\/your\/asset.fbx&quot;<\/p>\n<p>import_task.destination_path = &quot;\/Game\/YourFolder&quot;<\/p>\n<p>import_task.automated = True<\/p>\n<p>asset_tools.import_asset_tasks([import_task])<\/p>\n<h2><strong>\u91cd\u547d\u540d\u8d44\u4ea7<\/strong><\/h2>\n<p>asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()<\/p>\n<p>asset_registry.rename_assets([(&quot;\/Game\/YourFolder\/OldAssetName&quot;, &quot;\/Game\/YourFolder\/NewAssetName&quot;)])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u521b\u5efa\u548c\u4fee\u6539\u5173\u5361<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Python API\u6765\u521b\u5efa\u548c\u4fee\u6539\u5173\u5361\u4e2d\u7684\u5143\u7d20\uff0c\u4f8b\u5982\u6dfb\u52a0\u3001\u5220\u9664Actor\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u5173\u5361<\/strong><\/h2>\n<p>world = unreal.EditorLevelLibrary.get_editor_world()<\/p>\n<h2><strong>\u6dfb\u52a0\u4e00\u4e2a\u9759\u6001\u7f51\u683c\u4f53<\/strong><\/h2>\n<p>actor_location = unreal.Vector(0.0, 0.0, 0.0)<\/p>\n<p>actor_rotation = unreal.Rotator(0.0, 0.0, 0.0)<\/p>\n<p>static_mesh_actor = unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.StaticMeshActor, actor_location, actor_rotation)<\/p>\n<p>static_mesh_actor.set_actor_label(&quot;MyStaticMeshActor&quot;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u9759\u6001\u7f51\u683c<\/strong><\/h2>\n<p>static_mesh = unreal.EditorAssetLibrary.load_asset(&quot;\/Game\/YourStaticMesh&quot;)<\/p>\n<p>static_mesh_actor.static_mesh_component.set_static_mesh(static_mesh)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Python\u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177\uff0c\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5de5\u5177\u6765\u6279\u91cf\u5904\u7406\u8d44\u4ea7\u6216\u81ea\u52a8\u5316\u5e38\u89c1\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Unreal Engine\u7684Slate\u6846\u67b6\u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177\u7a97\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>class MyCustomTool:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.window = None<\/p>\n<p>    def create_window(self):<\/p>\n<p>        if self.window is None:<\/p>\n<p>            self.window = unreal.SWindow()<\/p>\n<p>            self.window.set_title(&quot;My Custom Tool&quot;)<\/p>\n<p>            self.window.set_content(self.build_ui())<\/p>\n<p>            unreal.EditorUtilityLibrary.add_window(self.window)<\/p>\n<p>    def build_ui(self):<\/p>\n<p>        vertical_box = unreal.SVerticalBox()<\/p>\n<p>        button = unreal.SButton()<\/p>\n<p>        button.set_text(&quot;Click Me&quot;)<\/p>\n<p>        button.set_on_clicked(self.on_button_clicked)<\/p>\n<p>        vertical_box.add_child(button)<\/p>\n<p>        return vertical_box<\/p>\n<p>    def on_button_clicked(self):<\/p>\n<p>        unreal.log(&quot;Button clicked!&quot;)<\/p>\n<p>        return unreal.SButtonReply.handled()<\/p>\n<p>tool = MyCustomTool()<\/p>\n<p>tool.create_window()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6279\u91cf\u5904\u7406\u8d44\u4ea7<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Python\u811a\u672c\u6765\u6279\u91cf\u5904\u7406\u8d44\u4ea7\uff0c\u4f8b\u5982\u91cd\u547d\u540d\u3001\u79fb\u52a8\u6216\u5220\u9664\u8d44\u4ea7\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>def batch_rename_assets(asset_path, old_name, new_name):<\/p>\n<p>    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()<\/p>\n<p>    assets = asset_registry.get_assets_by_path(asset_path, recursive=True)<\/p>\n<p>    for asset in assets:<\/p>\n<p>        if old_name in asset.asset_name:<\/p>\n<p>            new_asset_name = asset.asset_name.replace(old_name, new_name)<\/p>\n<p>            new_asset_path = f&quot;{asset.package_path}\/{new_asset_name}&quot;<\/p>\n<p>            unreal.EditorAssetLibrary.rename_asset(asset.object_path, new_asset_path)<\/p>\n<p>batch_rename_assets(&quot;\/Game\/YourFolder&quot;, &quot;OldName&quot;, &quot;NewName&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001Python\u4e0e\u84dd\u56fe\u7ed3\u5408<\/h3>\n<\/p>\n<p><p>Python\u811a\u672c\u53ef\u4ee5\u4e0eUnreal Engine\u7684\u84dd\u56fe\u7cfb\u7edf\u7ed3\u5408\u4f7f\u7528\uff0c\u4ee5\u521b\u5efa\u66f4\u590d\u6742\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h4>1. \u8c03\u7528\u84dd\u56fe\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u8c03\u7528\u84dd\u56fe\u4e2d\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<h2><strong>\u83b7\u53d6\u84dd\u56fe\u7c7b<\/strong><\/h2>\n<p>blueprint_class = unreal.EditorAssetLibrary.load_blueprint_class(&quot;\/Game\/YourBlueprint&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u84dd\u56fe\u5b9e\u4f8b<\/strong><\/h2>\n<p>blueprint_instance = unreal.EditorLevelLibrary.spawn_actor_from_class(blueprint_class, unreal.Vector(0.0, 0.0, 0.0))<\/p>\n<h2><strong>\u8c03\u7528\u84dd\u56fe\u51fd\u6570<\/strong><\/h2>\n<p>unreal.EditorUtilityLibrary.call_function_by_name_with_arguments(blueprint_instance, &quot;YourFunctionName&quot;, [&quot;Argument1&quot;, &quot;Argument2&quot;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5728\u84dd\u56fe\u4e2d\u8c03\u7528Python\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728\u84dd\u56fe\u4e2d\u8c03\u7528Python\u51fd\u6570\uff0c\u4ee5\u5b9e\u73b0\u66f4\u590d\u6742\u7684\u529f\u80fd\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u521b\u5efa\u4e00\u4e2aPython\u51fd\u6570\uff0c\u5e76\u4f7f\u7528<code>unreal<\/code>\u6a21\u5757\u4e2d\u7684\u88c5\u9970\u5668\u5c06\u5176\u6ce8\u518c\u4e3a\u84dd\u56fe\u8282\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>@unreal.uclass()<\/p>\n<p>class MyPythonFunctionLibrary(unreal.BlueprintFunctionLibrary):<\/p>\n<p>    @unreal.ufunction(static=True, blueprint_callable=True)<\/p>\n<p>    def my_python_function(arg1, arg2):<\/p>\n<p>        unreal.log(f&quot;Arg1: {arg1}, Arg2: {arg2}&quot;)<\/p>\n<p>        return arg1 + arg2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u84dd\u56fe\u4e2d\u4f7f\u7528\u201c\u8c03\u7528Python\u51fd\u6570\u201d\u8282\u70b9\u6765\u8c03\u7528\u8fd9\u4e2aPython\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u81ea\u52a8\u5316\u5de5\u4f5c\u6d41\u7a0b<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528Python\u811a\u672c\u81ea\u52a8\u5316\u5de5\u4f5c\u6d41\u7a0b\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u751f\u4ea7\u529b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u81ea\u52a8\u5316\u5de5\u4f5c\u6d41\u7a0b\u7684\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>1. \u81ea\u52a8\u5316\u5bfc\u5165\u548c\u8bbe\u7f6e\u8d44\u4ea7<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u81ea\u52a8\u5316\u5bfc\u5165\u548c\u8bbe\u7f6e\u8d44\u4ea7\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>def import_and_setup_assets(asset_folder, destination_path):<\/p>\n<p>    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()<\/p>\n<p>    import_task = unreal.AssetImportTask()<\/p>\n<p>    import_task.filename = asset_folder<\/p>\n<p>    import_task.destination_path = destination_path<\/p>\n<p>    import_task.automated = True<\/p>\n<p>    asset_tools.import_asset_tasks([import_task])<\/p>\n<p>    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()<\/p>\n<p>    assets = asset_registry.get_assets_by_path(destination_path, recursive=True)<\/p>\n<p>    for asset in assets:<\/p>\n<p>        # \u8bbe\u7f6e\u8d44\u4ea7\u5c5e\u6027<\/p>\n<p>        static_mesh = unreal.EditorAssetLibrary.load_asset(asset.object_path)<\/p>\n<p>        static_mesh.set_editor_property(&quot;collision_trace_flag&quot;, unreal.CollisionTraceFlag.CTF_USE_COMPLEX_AS_SIMPLE)<\/p>\n<p>import_and_setup_assets(&quot;path\/to\/your\/assets&quot;, &quot;\/Game\/YourFolder&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u6279\u91cf\u5904\u7406\u5173\u5361<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u6279\u91cf\u5904\u7406\u5173\u5361\uff0c\u4f8b\u5982\u6279\u91cf\u6dfb\u52a0\u6216\u5220\u9664Actor\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>def batch_add_actor_to_levels(actor_class, levels):<\/p>\n<p>    for level in levels:<\/p>\n<p>        world = unreal.EditorLevelLibrary.load_level(level)<\/p>\n<p>        actor_location = unreal.Vector(0.0, 0.0, 0.0)<\/p>\n<p>        actor_rotation = unreal.Rotator(0.0, 0.0, 0.0)<\/p>\n<p>        actor = unreal.EditorLevelLibrary.spawn_actor_from_class(actor_class, actor_location, actor_rotation)<\/p>\n<p>        actor.set_actor_label(&quot;BatchAddedActor&quot;)<\/p>\n<p>levels = [&quot;\/Game\/YourLevel1&quot;, &quot;\/Game\/YourLevel2&quot;]<\/p>\n<p>batch_add_actor_to_levels(unreal.StaticMeshActor, levels)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u8c03\u8bd5\u548c\u4f18\u5316Python\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u8c03\u8bd5\u548c\u4f18\u5316Python\u811a\u672c\u53ef\u4ee5\u5e2e\u52a9\u4f60\u53d1\u73b0\u5e76\u89e3\u51b3\u95ee\u9898\uff0c\u63d0\u9ad8\u811a\u672c\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u65e5\u5fd7\u548c\u65ad\u70b9<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528<code>unreal.log<\/code>\u51fd\u6570\u6253\u5370\u65e5\u5fd7\u6d88\u606f\uff0c\u5e2e\u52a9\u4f60\u8c03\u8bd5\u811a\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>def example_function():<\/p>\n<p>    unreal.log(&quot;This is a log message.&quot;)<\/p>\n<p>    # \u65ad\u70b9<\/p>\n<p>    breakpoint()<\/p>\n<p>example_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f18\u5316\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u4f18\u5316Python\u811a\u672c\u7684\u6027\u80fd\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u6279\u91cf\u64cd\u4f5c\u6765\u51cf\u5c11API\u8c03\u7528\u6b21\u6570\uff0c\u6216\u8005\u4f7f\u7528\u591a\u7ebf\u7a0b\u6765\u5e76\u884c\u5904\u7406\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>import threading<\/p>\n<p>def batch_process_assets(asset_paths):<\/p>\n<p>    for asset_path in asset_paths:<\/p>\n<p>        asset = unreal.EditorAssetLibrary.load_asset(asset_path)<\/p>\n<p>        # \u6279\u91cf\u5904\u7406\u8d44\u4ea7<\/p>\n<p>        asset.set_editor_property(&quot;some_property&quot;, &quot;new_value&quot;)<\/p>\n<p>def process_assets_in_threads(asset_paths, num_threads=4):<\/p>\n<p>    chunk_size = len(asset_paths) \/\/ num_threads<\/p>\n<p>    threads = []<\/p>\n<p>    for i in range(num_threads):<\/p>\n<p>        start = i * chunk_size<\/p>\n<p>        end = start + chunk_size if i != num_threads - 1 else len(asset_paths)<\/p>\n<p>        thread = threading.Thread(target=batch_process_assets, args=(asset_paths[start:end],))<\/p>\n<p>        threads.append(thread)<\/p>\n<p>        thread.start()<\/p>\n<p>    for thread in threads:<\/p>\n<p>        thread.join()<\/p>\n<p>asset_paths = [&quot;\/Game\/YourAsset1&quot;, &quot;\/Game\/YourAsset2&quot;, &quot;\/Game\/YourAsset3&quot;]<\/p>\n<p>process_assets_in_threads(asset_paths)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516b\u3001\u5b66\u4e60\u8d44\u6e90\u548c\u793e\u533a\u652f\u6301<\/h3>\n<\/p>\n<p><p>\u5b66\u4e60\u548c\u638c\u63e1Unreal Engine\u4e2d\u7684Python\u7f16\u7a0b\u9700\u8981\u4e0d\u65ad\u5730\u5b66\u4e60\u548c\u5b9e\u8df5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6709\u7528\u7684\u8d44\u6e90\u548c\u793e\u533a\u652f\u6301\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b98\u65b9\u6587\u6863<\/h4>\n<\/p>\n<p><p>Unreal Engine\u7684\u5b98\u65b9\u6587\u6863\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684Python API\u53c2\u8003\u548c\u793a\u4f8b\u4ee3\u7801\uff0c\u662f\u5b66\u4e60Python\u7f16\u7a0b\u7684\u6700\u4f73\u8d44\u6e90\u3002<\/p>\n<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.unrealengine.com\/en-US\/PythonAPI\/index.html\">Unreal Engine Python API<\/a><\/li>\n<li><a href=\"https:\/\/docs.unrealengine.com\/en-US\/ProgrammingAndScripting\/ProgrammingWithPython\/index.html\">Unreal Engine Python Scripting<\/a><\/li>\n<\/ul>\n<p><h4>2. \u793e\u533a\u8bba\u575b\u548c\u8ba8\u8bba\u7ec4<\/h4>\n<\/p>\n<p><p>\u52a0\u5165Unreal Engine\u7684\u793e\u533a\u8bba\u575b\u548c\u8ba8\u8bba\u7ec4\uff0c\u53ef\u4ee5\u4e0e\u5176\u4ed6\u5f00\u53d1\u8005\u4ea4\u6d41\u7ecf\u9a8c\uff0c\u83b7\u53d6\u5e2e\u52a9\u548c\u652f\u6301\u3002<\/p>\n<\/p>\n<ul>\n<li><a href=\"https:\/\/forums.unrealengine.com\/\">Unreal Engine Forums<\/a><\/li>\n<li><a href=\"https:\/\/answers.unrealengine.com\/\">Unreal Engine AnswerHub<\/a><\/li>\n<li><a href=\"https:\/\/discord.com\/invite\/unrealengine\">Unreal Engine Discord<\/a><\/li>\n<\/ul>\n<p><h4>3. \u5728\u7ebf\u8bfe\u7a0b\u548c\u6559\u7a0b<\/h4>\n<\/p>\n<p><p>\u53c2\u52a0\u5728\u7ebf\u8bfe\u7a0b\u548c\u89c2\u770b\u6559\u7a0b\u89c6\u9891\uff0c\u53ef\u4ee5\u7cfb\u7edf\u5730\u5b66\u4e60Unreal Engine\u4e2d\u7684Python\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<ul>\n<li><a href=\"https:\/\/www.udemy.com\/course\/unreal-engine-python-scripting\/\">Udemy &#8211; Unreal Engine Python<\/a><\/li>\n<li><a href=\"https:\/\/www.youtube.com\/results?search_query=unreal+engine+python+tutorials\">YouTube &#8211; Unreal Engine Python Tutorials<\/a><\/li>\n<\/ul>\n<p><h3>\u4e5d\u3001\u5b9e\u9645\u5e94\u7528\u6848\u4f8b<\/h3>\n<\/p>\n<p><p>\u4e86\u89e3\u4e00\u4e9b\u5b9e\u9645\u5e94\u7528\u6848\u4f8b\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528Python\u7f16\u7a0b\u3002<\/p>\n<\/p>\n<p><h4>1. <a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/23316.html\" target=\"_blank\">\u9879\u76ee\u7ba1\u7406<\/a>\u5de5\u5177<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u6765\u7ba1\u7406\u9879\u76ee\uff0c\u4f8b\u5982\u81ea\u52a8\u751f\u6210\u9879\u76ee\u7ed3\u6784\u3001\u7ba1\u7406\u8d44\u4ea7\u548c\u5173\u5361\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import unreal<\/p>\n<p>def create_project_structure(base_path):<\/p>\n<p>    folders = [<\/p>\n<p>        &quot;\/Game\/Assets&quot;,<\/p>\n<p>        &quot;\/Game\/Blueprints&quot;,<\/p>\n<p>        &quot;\/Game\/Materials&quot;,<\/p>\n<p>        &quot;\/Game\/Textures&quot;<\/p>\n<p>    ]<\/p>\n<p>    for folder in folders:<\/p>\n<p>        folder_path = os.path.join(base_path, folder)<\/p>\n<p>        if not os.path.exists(folder_path):<\/p>\n<p>            os.makedirs(folder_path)<\/p>\n<p>            unreal.log(f&quot;Created folder: {folder_path}&quot;)<\/p>\n<p>create_project_structure(&quot;path\/to\/your\/project&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u81ea\u52a8\u5316\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528Python\u811a\u672c\u7f16\u5199\u81ea\u52a8\u5316\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u9879\u76ee\u7684\u8d28\u91cf\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unreal<\/p>\n<p>def run_automated_tests():<\/p>\n<p>    test_framework = unreal.AutomationLibrary()<\/p>\n<p>    test_results = test_framework.run_tests(&quot;Functional Tests&quot;)<\/p>\n<p>    for result in test_results:<\/p>\n<p>        unreal.log(f&quot;Test: {result.test_name}, Result: {result.result}&quot;)<\/p>\n<p>run_automated_tests()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Unreal Engine\u4e2d\u4f7f\u7528Python\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u751f\u4ea7\u529b\u3002\u901a\u8fc7<strong>\u542f\u7528Python\u63d2\u4ef6\u3001\u7f16\u5199Python\u811a\u672c\u3001\u4f7f\u7528Python API\u3001\u521b\u5efa\u81ea\u5b9a\u4e49\u5de5\u5177\u3001\u4e0e\u84dd\u56fe\u7ed3\u5408\u3001\u81ea\u52a8\u5316\u5de5\u4f5c\u6d41\u7a0b\u3001\u8c03\u8bd5\u548c\u4f18\u5316\u811a\u672c<\/strong>\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u8bb8\u591a\u590d\u6742\u7684\u529f\u80fd\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u3002\u540c\u65f6\uff0c\u5229\u7528\u5b66\u4e60\u8d44\u6e90\u548c\u793e\u533a\u652f\u6301\uff0c\u4e0d\u65ad\u63d0\u5347\u81ea\u5df1\u7684\u6280\u80fd\u548c\u77e5\u8bc6\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u5728Unreal Engine\u4e2d\u4f7f\u7528Python\uff0c\u5b9e\u73b0\u4f60\u7684\u521b\u610f\u548c\u9879\u76ee\u76ee\u6807\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Unreal Engine\u4e2d\u5b89\u88c5Python\u63d2\u4ef6\uff1f<\/strong><br \/>\u8981\u5728Unreal Engine\u4e2d\u4f7f\u7528Python\uff0c\u60a8\u9700\u8981\u9996\u5148\u786e\u4fdd\u5b89\u88c5\u4e86Python\u63d2\u4ef6\u3002\u53ef\u4ee5\u5728Unreal Engine\u7684\u7f16\u8f91\u5668\u4e2d\uff0c\u524d\u5f80\u201c\u7f16\u8f91\u201d\u83dc\u5355\uff0c\u9009\u62e9\u201c\u63d2\u4ef6\u201d\uff0c\u7136\u540e\u5728\u641c\u7d22\u6846\u4e2d\u8f93\u5165\u201cPython\u201d\u3002\u542f\u7528\u201cPython Editor Script Plugin\u201d\u540e\uff0c\u91cd\u542f\u7f16\u8f91\u5668\uff0c\u4fbf\u53ef\u4ee5\u5f00\u59cb\u4f7f\u7528Python\u811a\u672c\u3002<\/p>\n<p><strong>\u5728Unreal Engine\u4e2d\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\u7684\u57fa\u672c\u6b65\u9aa4\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u7f16\u5199Python\u811a\u672c\u65f6\uff0c\u53ef\u4ee5\u5728\u7f16\u8f91\u5668\u5185\u4f7f\u7528\u201cPython\u63a7\u5236\u53f0\u201d\u8fdb\u884c\u4ea4\u4e92\u3002\u6253\u5f00\u63a7\u5236\u53f0\u540e\uff0c\u60a8\u53ef\u4ee5\u8f93\u5165\u7b80\u5355\u7684Python\u547d\u4ee4\u6765\u64cd\u63a7\u573a\u666f\u5143\u7d20\uff0c\u4f8b\u5982\u521b\u5efa\u5bf9\u8c61\u6216\u4fee\u6539\u5c5e\u6027\u3002\u4e5f\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa.py\u6587\u4ef6\uff0c\u5c06\u5176\u653e\u7f6e\u5728\u9879\u76ee\u7684Scripts\u6587\u4ef6\u5939\u4e2d\uff0c\u5e76\u5728\u63a7\u5236\u53f0\u4e2d\u8fd0\u884c\u8be5\u811a\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5Unreal Engine\u4e2d\u7684Python\u811a\u672c\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u811a\u672c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528Python\u7684\u5185\u7f6e\u8c03\u8bd5\u5de5\u5177\uff0c\u4f8b\u5982pdb\u6a21\u5757\u3002\u60a8\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u63d2\u5165\u65ad\u70b9\uff0c\u4f7f\u7528\u63a7\u5236\u53f0\u8f93\u51fa\u8c03\u8bd5\u4fe1\u606f\u3002\u540c\u65f6\uff0cUnreal Engine\u7684\u8f93\u51fa\u65e5\u5fd7\u4e5f\u4f1a\u663e\u793aPython\u6267\u884c\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u5e2e\u52a9\u60a8\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u5728Unreal Engine\u4e2d\u81ea\u52a8\u5316\u4efb\u52a1\u7684\u597d\u5904\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u501f\u52a9Python\u5728Unreal Engine\u4e2d\u81ea\u52a8\u5316\u4efb\u52a1\uff0c\u60a8\u53ef\u4ee5\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\uff0c\u51cf\u5c11\u624b\u52a8\u64cd\u4f5c\u7684\u91cd\u590d\u6027\u3002Python\u53ef\u4ee5\u7528\u6765\u6279\u91cf\u5904\u7406\u8d44\u6e90\u3001\u751f\u6210\u5173\u5361\u5143\u7d20\u3001\u5bfc\u5165\u6570\u636e\u7b49\uff0c\u4ece\u800c\u4f7f\u5f00\u53d1\u8fc7\u7a0b\u66f4\u52a0\u6d41\u7545\uff0c\u5c24\u5176\u5728\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u80fd\u591f\u663e\u8457\u8282\u7701\u65f6\u95f4\u548c\u7cbe\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728UE\uff08Unreal Engine\uff09\u4e2d\u4f7f\u7528Python\u53ef\u4ee5\u901a\u8fc7\u542f\u7528Python\u63d2\u4ef6\u3001\u7f16\u5199Python\u811a\u672c\u3001\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1170587,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1170584"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1170584"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1170584\/revisions"}],"predecessor-version":[{"id":1170588,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1170584\/revisions\/1170588"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1170587"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1170584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1170584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1170584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}