Download

Python issues

I wanted to share with everyone my struggle to get Python working in Unreal 4. This is where I am at and I am looking to make Epic aware of what is not working.

  • Open Unreal 4.20.2
  • Load the map into the editor Minimal_Default that ships with Unreal
  • Load the Python Editor Script Plugin

Example:

Switch to the Python command line in the Output Log:

Select a few objects in the scene. Here I selected the table and chair.

Next copy and paste and execute each of these chunks of code. You have to do it in chunks because the input lines are limited to 10 max I think.


import unreal
level_path = '/Game/StarterContent/Maps/Minimal_Default'
level = unreal.find_asset(name=level_path)
selectionIter = unreal.SelectedActorIterator(level)
selectionNames = ]


while True:
                node = None
                try: node = selectionIter.next()
                except: break

                # get node data
                nodeName = node.get_name()
                selectionNames.append(nodeName)


print 'Selected nodes in scene = ', selectionNames


The result of these three chunks will show this in the log:

20180828_11h57_05.png

The log will print that you have the Table and Chair selected! Nice!

Now execute this line of code:


print help(unreal.SelectedActorIterator)


20180828_11h58_19.png

This will show you what methods are available to SelectedActorIterator. Many of the help documentation looks like it is still being setup so this is not necessarily ever function available to you.

Now execute this line of code:


print help(unreal.EditorStaticMeshLibrary)


20180828_11h59_03.png

Uh oh! What happened! It looks like the tutorials that are listed in the Unreal documentation show functions that do not yet exist inside of the Python unreal module.

Example:

https://docs.unrealengine.com/en-us/…ints-or-Python

The documentation shows this code:



 import unreal  asset_path = "/Game/studio"  # we define a function that generates new LODs for a specified Static Mesh Asset. def apply_lods(static_mesh):      # check if the mesh is complex enough.     number_of_vertices = unreal.EditorStaticMeshLibrary.get_number_verts(static_mesh, 0) 

However EditorStaticMeshLibrary does not exist as I showed above.

HELP!
Thanks!
Ryan

Hey Ryan,
the EditorStaticMeshLibrary is available in the EditorScriptingUtilties plugin. If you install that plugin for your project, you should get access to that class.

As that doc page says:

Prerequisite: If you haven’t already done so, you’ll need to install the Editor Scripting Utilities Plugin. For details, see Scripting and Automating the Editor.

Also, FYI, we’ve published a browsable, autogenerated version of the API docs at:
https://api.unrealengine.com/INT/PythonAPI/

Hope that helps.