# Getting nested struct value from blueprint variables with python?

**URL:** <https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [August 2, 2019, 11:19pm UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490 "2019-08-02T23:19:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CraveTheGrave](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CraveTheGrave](https://forums.unrealengine.com/u/CraveTheGrave)\
**Post date:** [August 2, 2019, 11:19pm UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/1 "2019-08-02T23:19:19Z")

</div>

I’m attempting something similar to [https://forums.unrealengine.com/deve…le-from-python](https://forums.unrealengine.com/development-discussion/python-scripting/1591378-can-you-edit-a-blueprint-variable-from-python)

Basically I want to copy the default values of a blueprint’s struct variable (the defaults of the struct as set in the BP defaults, not the struct definition defaults) so I can use them to change other game settings with a script.

Right now I’m trying to get the nested struct value with

```auto

blueprint = unreal.load_object(None, '/Game/Blueprints/XYZGameMode_BP.XYZGameMode_BP_C')
bp_cdo = unreal.get_default_object(blueprint)
print bp_cdo.get_editor_property("LevelData").get_editor_property("NestedValue")

```

But that fails with **[FONT=courier new]`Exception: StructBase: Failed to find property...`**. I can’t seem to get at the internal struct values in any way.

I should note that when I do something like “bp\_cdo.get\_editor\_property(“StringVariable”)” the default value returns just fine.

Is what I’m trying to do possible?

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [August 3, 2019, 12:04am UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/2 "2019-08-03T00:04:26Z")

</div>

If LevelData is a struct instance then that should work. How is your struct type defined?

User Defined Structs (structs defined as assets) use mangled internal names for properties, and I suspect that it would be impossible to find them from Python as things currently stand, though C++ defined structs should work just fine.

---

<div class="post-metadata">

**Author:** ![CraveTheGrave](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CraveTheGrave](https://forums.unrealengine.com/u/CraveTheGrave)\
**Post date:** [August 9, 2019, 8:31pm UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/3 "2019-08-09T20:31:43Z")

</div>

Thanks for the definitive reply, Jamie. In our case they are User Defined, but we could port them to C++ or move the data elsewhere easily 🙂

---

<div class="post-metadata">

**Author:** ![dan07070707](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dan07070707](https://forums.unrealengine.com/u/dan07070707)\
**Post date:** [November 5, 2022, 4:39pm UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/4 "2022-11-05T16:39:27Z")

</div>

> [@CraveTheGrave](#):
>
> `bp_cdo.get_editor_property("LevelData").get_editor_property("NestedValue")`

Did you find a solution to this in python?

---

<div class="post-metadata">

**Author:** ![pearshapedzhang](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pearshapedzhang/32/596802_2.png) [@pearshapedzhang](https://forums.unrealengine.com/u/pearshapedzhang)\
**Post date:** [March 28, 2023, 8:11am UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/5 "2023-03-28T08:11:08Z")

</div>

The only way worked for me is to extend python with C++.  
Make sure the struct type is Blueprintable, by adding macro USTRUCT(Blueprintable). Then in my blueprint function library plugin, I defined my own C++ functions to read and write the user defined struct type variables. And finally I could access the data I wanted with Python back in editor…

---

<div class="post-metadata">

**Author:** ![MrHardo1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MrHardo1](https://forums.unrealengine.com/u/MrHardo1)\
**Post date:** [April 22, 2024, 2:30am UTC](https://forums.unrealengine.com/t/getting-nested-struct-value-from-blueprint-variables-with-python/129490/6 "2024-04-22T02:30:08Z")

</div>

Thought I’d elaborate further for anyone googling:

I’m trying to write a python script that modifies the members of a user-created struct.

It seems you _cannot_ accomplish this with blueprint-created structs. Attempting to do so always results in “Failed to find property” error.

However, doing this with C++ is trivial. For instance, say I created the following struct in C++:

```auto
USTRUCT(BlueprintType)
struct FItemTest
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float FloatTest;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString StringTest;
	
};

```

I add this struct to a blueprint class. Now, to modify the default value of the struct, I run the following python script:

```auto
import unreal
bp_object = unreal.EditorAssetLibrary.load_blueprint_class('/Game/ProjectName/Characters/NPC_Test')
bp_default_object = unreal.get_default_object(bp_object)
bp_default_object.get_editor_property("ItemTest").set_editor_property("FloatTest", 1)

```

This successfully modifies the “FloatTest” struct member and sets the value to 1.
