Announcement

Collapse
No announcement yet.

Creating blueprint assets/hierarchies with Python.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating blueprint assets/hierarchies with Python.

    Hey there,

    is it possible to create a blueprint/actor in the content browser with python, like you do normally with right-click, create blueprint class, actor? Also I want to apply (mesh) components to it (with Python), so I can drag and drop a mesh-collection into the scene.
    I tried something with assetTool.create_asset for creating an actor, but I am stuck with the factory argument.

    Furthermore, it would be interesting to create an actorstructure while importing, as you can see here but it seams like this function is not supported yet. (just getting errors)

    Thank you in advance for your answers and time!
    Last edited by Elias Kremer; 09-05-2018, 08:04 AM.

    #2
    Hey, I had to go back to the dev team to ask about this one. Turns out that it is possible to create a new Blueprint, like this:

    Code:
    import unreal
    
    asset_name = "MyAwesomeBPActorClass"
    package_path = "/Game/MyContentFolder"
    
    factory = unreal.BlueprintFactory()
    factory.set_editor_property("ParentClass", unreal.Actor)
    
    asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
    my_new_asset = asset_tools.create_asset(asset_name, package_path, None, factory)
    
    unreal.EditorAssetLibrary.save_loaded_asset(my_new_asset)
    but it doesn't look like there's a way to add components to the asset.

    Comment


      #3
      Thank you! This helps me a lot.

      Comment


        #4
        I hope the whole BluePrint APIs will be exposed to Python. It would be very useful if it was possible to code everything BluePrint related directly in Python. Coding complex algorithms with Python using BluePrints would be way easier than having to do it visually with all the spaghetti mess.

        Comment


          #5
          Actually that is the case already. Virtually everything that is exposed to Blueprint is also exposed to Python. The only real limitation is that Python is intended (at least for now) to be exclusively for editor scripting, not for runtime. So it's great for things like preparing assets in the UE4 editor, setting up a pipeline that connects UE4 to other external tools, laying out a level programmatically, etc. Were you hoping to be able to use it as a runtime scripting language?

          Comment


            #6
            Originally posted by Robb Surridge View Post
            Actually that is the case already. Virtually everything that is exposed to Blueprint is also exposed to Python. The only real limitation is that Python is intended (at least for now) to be exclusively for editor scripting, not for runtime. So it's great for things like preparing assets in the UE4 editor, setting up a pipeline that connects UE4 to other external tools, laying out a level programmatically, etc. Were you hoping to be able to use it as a runtime scripting language?
            In another thread it was replied to me that it wasn't planned to be able to create BluePrint code using Python because full BluePrint APIs weren't exposed. If that changed then it would be really useful being able to code visual BluePrints spaghetti algorithms with Python script code. Still in editor will it be possible to even translate existing BluePrints to Python scripting for further editing thru Python? Or is Python scripting working on existing BluePrints and not just for creating new ones so that full editing and so coding could be done thru Python then? If runtime support will be added in the future too that would be great too.

            Comment


              #7
              It depends what you mean by "able to create BluePrint code using Python":

              If you mean, can I write a Python script that has the same effect as any given Blueprint graph, the answer is almost always yes.
              If you mean, can I write a Python script that outputs a graph of Blueprint nodes, then no.

              Python is an alternative to Blueprint that exposes mostly the same set of API functions in a different language. But there isn't a way to translate code automatically back and forth from one to the other. You can't take a Blueprint graph and say "Give me this as a Python script," or vice-versa. That would be neat, but for the time being you need to work in one or the other.

              Runtime use is tricky for a few reasons, including performance. For now, we're mostly hearing that the need for Python is more on the data prep, production and interop side. If you're looking for an alternative to Blueprints for runtime, you could always try to take the plunge into C++.

              Comment


                #8
                Originally posted by Robb Surridge View Post
                It depends what you mean by "able to create BluePrint code using Python":

                If you mean, can I write a Python script that has the same effect as any given Blueprint graph, the answer is almost always yes.
                If you mean, can I write a Python script that outputs a graph of Blueprint nodes, then no.
                Sorry but then that means that it still is not possible to use Python scripts to create anything BluePrints related... or not?
                You are telling me that it is not possible to code BluePrint collapsed Functions/Macros with Python, right? Only basic BluePrint graphs are supported thru Python scripts then?

                Python is an alternative to Blueprint that exposes mostly the same set of API functions in a different language. But there isn't a way to translate code automatically back and forth from one to the other. You can't take a Blueprint graph and say "Give me this as a Python script," or vice-versa. That would be neat, but for the time being you need to work in one or the other.
                Well, I hope that that will be a planned feature for future versions then. It would be really useful to not have to modify any BluePrint code visually but using Python instead and then regenerate the BluePrint visual code thru any modifications made with Python scripts. It would allow to quickly browse thru a lot of complex BP code and being able to write it at a practically infinite complexity as needed thanks to Python. Something that a human really wouldn't be able to manage doing visually with BPs otherwise.

                Runtime use is tricky for a few reasons, including performance. For now, we're mostly hearing that the need for Python is more on the data prep, production and interop side. If you're looking for an alternative to Blueprints for runtime, you could always try to take the plunge into C++.
                If only public documents for the C++ were all clearly up to date with all the APIs explained then I would use that indeed but for many things in UE4 using BluePrints became mandatory anyway more or less. The problem is with writing or modifying complex algorithm in visual spaghetti code using BluePrints that becomes a nightmare compared to text based standard script or programming languages. I can understand using BPs for accessing APIs quicker for simple things but when algorithms become very complex and you have to waste a lot of time just to follow how a graph is visually built trying to understand what the actual code does then it becomes a problem. It can be a problem with C++ and other languages too indeed when not properly commented but it is still less messed up than wandering thru many visual graphs (which is the same issue affecting things like UML and such I'd say...)

                Comment


                  #9
                  It would be really useful to not have to modify any BluePrint code visually but using Python instead and then regenerate the BluePrint visual code thru any modifications made with Python scripts..
                  I have a (currently on hold) R&D system that can do that. I'm still in research phase...

                  * but it's not Python tho *
                  ​​​​​
                  | Finite State Machine | Auto-Save Plugin | USQLite Plugin | Object-Pool | Sound-Occlusion | Anti-Cheat Plugin | Property Transfer Tool | Magic Nodes |

                  Comment


                    #10
                    Originally posted by BrUnO XaVIeR View Post
                    I have a (currently on hold) R&D system that can do that. I'm still in research phase...

                    * but it's not Python tho *
                    Great to hear, what language do you use to make bluprints scriptable in a round-trip fashion?
                    Get your GAME done - Productivity Plugins for Unreal Engine.

                    My articles in Game Programming Gems:
                    Real Time Modular Audio Processing For Games
                    A Lightweight Generator for Real-Time Sound Effects
                    Controlling Real-Time Sound Synthesis from Game Physics

                    Comment


                      #11
                      It's a hobby project just 4fun.
                      There's no "language" or pre-existing scripting language API like Python's embedded interpreter...

                      I'm studying the concepts behind runtime scripting languages and compilers; so basically I am creating my own "language", my own lexer, and my own parser/compiler that can take a script and convert it to a Blueprint Node or execute script at runtime loaded from a text file on a folder.

                      (I want to build a weird game that can compile scripts at runtime so I begun researching this around 2016).


                      I'm just saying it's very possible so probably down the road Epic might do the same thing with Python
                      | Finite State Machine | Auto-Save Plugin | USQLite Plugin | Object-Pool | Sound-Occlusion | Anti-Cheat Plugin | Property Transfer Tool | Magic Nodes |

                      Comment


                        #12
                        Wanted to bump this post. Thank you for the tip on creating blueprints via python.

                        I agree with the OP that it would be very helpful to A) add components to blueprints via python and B) Add and connect Blueprint nodes in Blueprint graphs via Python. In my mind, this is part of the asset prep pipeline. Is it still Epic's plan not to support this?

                        Comment


                          #13
                          So I have a blueprint that has a default scene root with a bunch of static meshes all underneath it (its a building). Each of these static meshes has a name like A, B, C, D, E, etc. I would like to rename this as "generated_A", "generated_B". So I want to be able to load a blue print, access its components, and then rename them. I can do this through the gui by double clicking the blueprint asset (open up a blue print editor), Looking at the scene graph on the left, and right clicking each static mesh and renaming it.

                          Any way to automate this.?

                          Here is some example code that only renames the entire blue print asset, not the indivual static compoennts

                          from unreal import EditorAssetLibrary as ual, EditorLevelLibrary as ull, Vector, Rotator
                          obj1 = ual.load_asset("/Game/UrbanCity/Models/ModularBuildings/Prefabs/Building1_Example")
                          obj1.rename("Generated_Buildings1_Example")

                          ## what i want
                          for component in obj1.get_components()
                          component.rename("generated_" + component.get_name())

                          Comment


                            #14
                            It doesn't look like we can get into the Blueprint class and rename its components.
                            You should be able to rename the components in the Actor once you drop an instance of that Blueprint class into your Level, but I don't see a way to do it on the Asset itself.

                            Here's a script that renames the components on a selected BP Actor in the Level:

                            Code:
                            import unreal
                            
                            actors = unreal.EditorLevelLibrary.get_selected_level_actors()
                            
                            for actor in actors:
                                sm_comps = actor.get_components_by_class(unreal.StaticMeshComponent)
                                for sm_comp in sm_comps:
                                    comp_name = sm_comp.get_name()
                                    sm_comp.rename("Generated " + comp_name)

                            Comment


                              #15
                              I'd like to see more snippets. A reference for small tasks like "create a blueprint" was great.

                              Is this a full-blown editor scripting API? Or just some surface-level tidbits to do the odd thing, like create a folder. If the functionality is limited, can I at least call code in my plug-in as a workaround?

                              Can I do stuff like this? https://github.com/20tab/UnrealEngin...tedPipeline.md
                              Last edited by cannabis.cod3r; 03-16-2019, 09:02 PM.

                              Comment

                              Working...
                              X