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 Plugin | Sound-Occlusion Plugin | Anti-Cheat Plugin |

                  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.

                    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 Plugin | Sound-Occlusion Plugin | Anti-Cheat Plugin |

                      Comment

                      Working...
                      X