# Access C++ UStruct from Python

**URL:** <https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [April 1, 2020, 1:11pm UTC](https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773 "2020-04-01T13:11:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EPG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@EPG](https://forums.unrealengine.com/u/EPG)\
**Post date:** [April 1, 2020, 1:11pm UTC](https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773/1 "2020-04-01T13:11:25Z")

</div>

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

> [@](#):
>
> class SWP\_VR\_API UMyComponent : public UActorComponent  
> {  
> public:
> 
> TArray\<FTInfo\> TLabels;  
> (…)  
> }

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:

> [@](#):
>
> comp = act.get\_components\_by\_class(ue.MyComponent)  
> comp[0].set\_editor\_property(“Name”, name)

---

<div class="post-metadata">

**Author:** ![huehuehue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@huehuehue](https://forums.unrealengine.com/u/huehuehue)\
**Post date:** [April 14, 2022, 12:07pm UTC](https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773/2 "2022-04-14T12:07:30Z")

</div>

Any updates on this one?

---

<div class="post-metadata">

**Author:** ![huehuehue](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@huehuehue](https://forums.unrealengine.com/u/huehuehue)\
**Post date:** [April 14, 2022, 12:25pm UTC](https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773/3 "2022-04-14T12:25:21Z")

</div>

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

```plaintext
import unreal

your_custom_struct = unreal.YourCustomUStruct()

```

Here is how it looked for me concretely

C++ struct def

```plaintext
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

```plaintext
import unreal

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

```

Cheers

---

<div class="post-metadata">

**Author:** ![Alvininorge](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alvininorge](https://forums.unrealengine.com/u/Alvininorge)\
**Post date:** [October 15, 2023, 8:30pm UTC](https://forums.unrealengine.com/t/access-c-ustruct-from-python/140773/4 "2023-10-15T20:30:55Z")

</div>

Hi,

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