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.

2 Likes

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!

1 Like

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

Take a look at this tutorial videos ~

1 Like

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.

2 Likes

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())

Texture dimensions in asset browser’s preview popup and columns view mode is imported size.
But blueprint_get_size returns Max In-Game property, affected by max texture size.

# if texture's imported dimensions was 1024x1024,
my_texture2d.set_editor_property('max_texture_size', 512)
print(my_texture2d.blueprint_get_size_x())  # 512
my_texture2d.set_editor_property('max_texture_size', 0)
print(my_texture2d.blueprint_get_size_x())  # 1024

If I reset max_texture_size = 0 to get imported size then revert, it seems the asset need to be regenerated twice.
Is there better way retrieve imported dimensions without changing its property?

Greetings @tsweeper ! We’re SO excited to welcome you to the Unreal Engine Community! We see that this is the first post you have made in our forums! :medal_sports:

As you can see, the last post on this topic is almost a year old. I do hope that the responses you seek will be noticed. If not, please feel free to post a new question in our forums! Thank you for being an important part of our growing community! Good Luck on your project and Happy Creating! :smiley:

This is such a useful snippet. I was wandering is there a way to narrow this down to only return what is in the current open level rather than the project as a whole?