Access C++ UStruct from Python

I have a C++ struct, that I store in an array of my own Component:

I want to edit this from a Python script. Is it possible? And if yes, how?

I had an FString type called Name and I could modify it easily:

1 Like

Any updates on this one?

Ok, solved it myself.

First you need to go to Editor Preferences and under “Python” enable “Developer Mode”.
After that, you can find all in Python available unreal types under <ProjectDirectory>\Intermediate\PythonStub\unreal.py

In your Python editor script, you can then access these types like this

import unreal

your_custom_struct = unreal.YourCustomUStruct()

Here is how it looked for me concretely

C++ struct def

USTRUCT(BlueprintType)
struct FMeshWithPickProbability
{
	GENERATED_BODY();

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Custom)
	class UStaticMesh* StaticMesh = nullptr;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Custom)
	int32 Probability = 1;
};

Python code

import unreal

# ...
mesh_with_pick_probability = unreal.MeshWithPickProbability(static_mesh=my_data_asset.mesh_building_block, probability=1)

Cheers

1 Like

Hi,

I tried the same as you did. I defined a custom USTRUCT in C++ and try to instantiate it in python by callingmy_struct = unreal.MyStruct() , but unreal python cannot find the named struct in its module. Do you know how to instantiate a custom struct?