# How to add a variable to a generated Blueprint?

**URL:** <https://forums.unrealengine.com/t/how-to-add-a-variable-to-a-generated-blueprint/2063092>\
**Category:** C++\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [October 11, 2024, 9:09am UTC](https://forums.unrealengine.com/t/how-to-add-a-variable-to-a-generated-blueprint/2063092 "2024-10-11T09:09:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JAuzanneau](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jauzanneau/32/978097_2.png) [@JAuzanneau](https://forums.unrealengine.com/u/JAuzanneau)\
**Post date:** [October 11, 2024, 9:09am UTC](https://forums.unrealengine.com/t/how-to-add-a-variable-to-a-generated-blueprint/2063092/1 "2024-10-11T09:09:13Z")

</div>

Hi, I’m wondering if it is possible and if so, how, to add a variable to a generated Blueprint.

Specifically, I’m creating BPs using C++. I want to add variables to the blueprint during the creation process, and then add Get and Set nodes inside the event graph.

- How do I add a variable to a UBlueprint object?
- Are there classes like UBlueprintNodeSpawner for variable nodes? (didn’t find any function name for a Get node)

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![JAuzanneau](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jauzanneau/32/978097_2.png) [@JAuzanneau](https://forums.unrealengine.com/u/JAuzanneau)\
**Post date:** [October 15, 2024, 2:58pm UTC](https://forums.unrealengine.com/t/how-to-add-a-variable-to-a-generated-blueprint/2063092/2 "2024-10-15T14:58:22Z")

</div>

I figured out a workaround that worked for me:

First, I created a blueprint from an Actor using `FKismetEditorUtilities::CreateBlueprintFromActor`.  
Then, I retrieved the BP’s component hierarchy as an array of `USCS_Node` using `Blueprint->SimpleConstructionScript->GetAllNodes()`.  
With this, I could iterate over the components and find the ones I need programmatically. Then, I created `UK2Node_VariableGet` nodes using `UBlueprintNodeSpawner` and set their MemberReference.

This is enough to programmatically add Getter nodes to an event graph.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 14, 2024, 2:59pm UTC](https://forums.unrealengine.com/t/how-to-add-a-variable-to-a-generated-blueprint/2063092/3 "2024-11-14T14:59:03Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
