# can you make reference from blueprint variable to c++ code?

**URL:** <https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611>\
**Category:** C++\
**Tags:** unreal-engine, CPP, Blueprint, question\
**Created:** [April 4, 2023, 4:54pm UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611 "2023-04-04T16:54:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 4, 2023, 4:54pm UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611/1 "2023-04-04T16:54:21Z")

</div>

Hello  
I’m quite noobie to Unreal c++ and are wondering, if i make a component for inventory and that is in c++ code and want to reference a UI by putting it in a variable in blueprint, is it possible for me to somehow reference UI variable from blueprint to a c++ code class or do i need to also make the UI a c++ code?

---

<div class="post-metadata">

**Author:** ![pladux](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pladux/32/1194519_2.png) [@pladux](https://forums.unrealengine.com/u/pladux)\
**Post date:** [April 4, 2023, 6:34pm UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611/2 "2023-04-04T18:34:47Z")

</div>

If you have a C++ component that has a property marked with UPROPERTY(BlueprintReadOnly) (or BlueprintReadWrite) you should be able to access that property from your Widget blueprint without problems. No need to use C++ for that. Your component might be declared as UCLASS(BlueprintType) in order to be assigned to a variable.

---

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 5, 2023, 6:16pm UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611/3 "2023-04-05T18:16:49Z")

</div>

how can i get access from it, do i just type the name in? like

variable in blueprint name: UI\_W

UPROPERTY(BlueprintReadWrite)  
UUserWidget\* UI\_W

is it something like this?

---

<div class="post-metadata">

**Author:** ![pladux](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pladux/32/1194519_2.png) [@pladux](https://forums.unrealengine.com/u/pladux)\
**Post date:** [April 5, 2023, 8:56pm UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611/4 "2023-04-05T20:56:10Z")

</div>

That would be having a reference of a widget inside of your C++ class. Isn’t that the opposite of what you are trying to achieve?

From my understanding you would want to have a widget blueprint that has a reference to your inventory component. So in the blueprint editor you would create a variable of type “inventory component” and make it public editable, may be even"expose on spawn".

Now after creating you can pass your inventory component over to your widget and use that to display its data.

---

<div class="post-metadata">

**Author:** ![emir143](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@emir143](https://forums.unrealengine.com/u/emir143)\
**Post date:** [April 6, 2023, 12:05am UTC](https://forums.unrealengine.com/t/can-you-make-reference-from-blueprint-variable-to-c-code/844611/5 "2023-04-06T00:05:37Z")

</div>

actually yes, you are correct, i get confused with these codes alot xd

so if i get it straight, i should:

1. create variable in bluepirnt
2. name it inventory component
3. make it public  
4.then assign either inventory component or the UI Widget
