# How to set variable in PlayerController from UserWidget?

**URL:** <https://forums.unrealengine.com/t/how-to-set-variable-in-playercontroller-from-userwidget/368751>\
**Category:** UI\
**Tags:** playercontroller, variables-communicat, unreal-engine, Widget, Blueprint, question\
**Created:** [August 30, 2016, 2:44pm UTC](https://forums.unrealengine.com/t/how-to-set-variable-in-playercontroller-from-userwidget/368751 "2016-08-30T14:44:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rusbaron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rusbaron](https://forums.unrealengine.com/u/Rusbaron)\
**Post date:** [August 30, 2016, 2:44pm UTC](https://forums.unrealengine.com/t/how-to-set-variable-in-playercontroller-from-userwidget/368751/1 "2016-08-30T14:44:47Z")

</div>

I’m making analog of PvZ game, and now i’m stuck at making working for user interface. So i have a button (User Widget)

 ![104924-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/c/6/0c69645c509e4cc145a7a778ee6aab024bc9872c.png)

And after pressing button i want to change variable in Player Controller, where i will compute closest TargetPoint to mouse and wait for a mouse click

 ![104925-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/5/e/85ea51cff8cc29ffa5609997dc920fbd36255809.png)

so,after mouse click i will create plant on closest to mouse target point.  
But how i can access PlayerController variable from User Widget?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_e729f54e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_e729f54e](https://forums.unrealengine.com/u/anonymous_user_e729f54e)\
**Post date:** [August 30, 2016, 3:16pm UTC](https://forums.unrealengine.com/t/how-to-set-variable-in-playercontroller-from-userwidget/368751/2 "2016-08-30T15:16:01Z")

</div>

Hello Rusbaron,

I would suggesting Getting a reference to the player controller (Get Player Controller) and then casting in order to get a reference to any variable that you would like to alter. I have provided a link to documentation that explains casting. I hope that this information helps.

Link: [https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/](https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/)

Make it a great day

---

<div class="post-metadata">

**Author:** ![Rusbaron](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rusbaron](https://forums.unrealengine.com/u/Rusbaron)\
**Post date:** [August 31, 2016, 7:22am UTC](https://forums.unrealengine.com/t/how-to-set-variable-in-playercontroller-from-userwidget/368751/3 "2016-08-31T07:22:09Z")

</div>

Thks!It works!
