Download

Python Property Finding or Listing

Good Morning.
Python being our pipeline automation interpreter of choice, have been getting the time to dig into Unreal 4 to give our artists some better ingestion and setup tools.
One aspect I have been having difficulty with for the past 5 days is a progmatic way to list what editor properties are available for the classes.
e.g. Material has everything from “Two Sided” to “Blend Mode”, however as a support developer, have not found a method to be able to list all the properties available in a class/node that is available.

There are get/set_editor_property methods.
Is there any methods of discovering what properties are available via Python script? Regardless of what node/Asset/Class you are setting a tool up for?

Thank you for any pointers or directions or even books to order to find this sort of information out.

Eureka! Discovered, or realized, the connection I was looking for!

The Classes or Nodes may not have a built in method to reveal what properties they have available, however the properties are the class attributes directly.
By looking at the API Class documentation, or doing a python dir of the class in question, you can see the properties available. Yes it will list everything, but you can easily see which property name it is you desire to make use of.

Obvious reminder, Definitely use the


<asset>.set_editor_property("<property>") 

methods to allow the editor to take care of extracurricular activities as needed.

Now off to figure out how to work with property connections!

you can write a C++ blueprint so that you can list the asset properties.

Take a look at this tutorial videos ~
https://www.youtube.com/watch?v=2GptXWIgwqI&list=PLBLmKCAjA25Br8cOVzUroqi_Nwipg-IdP&index=13

Yes. You can. Unsure as to how this would help with using Python and the “unreal” module?

OH… but bringing up a suggestion unrelated to the topic does remind me to update this post to state the solution.

Here is a snippet of code to gather the texture and material assets using Python and the built in “unreal” module.


def get_textures_and_materials():
"""
Return lists for all available Texture2D and Material assets.
"""
    all_assets = unreal.AssetRegistryHelpers.get_asset_registry().get_all_assets()
    textures = [x for x in all_assets if x.asset_class == 'Texture2D' and x.object_path.__str__().startswith('/Game/')]
    materials = [x for x in all_assets if x.asset_class == 'Material' and x.object_path.__str__().startswith('/Game/')]
    return textures, materials

textures, materials = get_textures_and_materials()

This will give you all the expected Texture2D and Material assets currently in your open project.
However keep in mind that these are the AssetData objects of the desired assets. So you need to reach in a little deeper in order to find the properties.
Lets get an actual asset. Lets just grab the first Material that would be in the list.


my_material = materials[0].get_asset()

The AssetData has a method called “get_asset()” that returns the actual asset class to work with.

Now that we have this, simply doing a “dir” will list all methods and attributes. Yes, this is a dump of just everything in that class, but it includes it’s attributes.
Alternately, you can go to that class’s page in the documentation, which lists all the available attributes you can get or set.
e.g.
https://docs.unrealengine.com/en-US/PythonAPI/class/Material.html

This provides the information this post was looking for.

Hopefully this will help someone new to the Unreal Python.

hey friends!
any methods to get the texture dimension?

https://docs.unrealengine.com/en-US/PythonAPI/class/Texture2D.html


#From the example above and assuming they are an array of texture2d objects
for texture in textures:
    print(texture.blueprint_get_size_x())
    print(texture.blueprint_get_size_y())