# How can I cast from a widget to a non-NPC character?

**URL:** <https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784>\
**Category:** UI\
**Tags:** interface, casting, dispatcher, cast-failed, unreal-engine, question, Blueprint\
**Created:** [July 6, 2017, 10:26pm UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784 "2017-07-06T22:26:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maladrum](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/maladrum/32/1013148_2.png) [@Maladrum](https://forums.unrealengine.com/u/Maladrum)\
**Post date:** [July 6, 2017, 10:26pm UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784/1 "2017-07-06T22:26:09Z")

</div>

I’m working through setting up a 1-on-1 card fighting system. However, for the moment, I’m simply using the Puzzle Template to damage my enemy whenever I click on one of the blocks. Before trying this, I set it up to do it on my own character, and it works perfectly. The following screenshots illustrate how I did this:

 ![201959-castissue1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/9/5/695a6c3255ce5a14c1ab2db1dbeef37c90e1a36c.png)

 ![201960-castissue2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/2/5f2f15efcfac0e8512cd023c3699bb7d8488783b.png)

Simple, really, and it works splendidly. Unfortunately, the same cannot be said for when I try to manage enemy damage with the same approach. This is simply because I obviously can’t plug in “cast to player character–\>get player character” into the EnemyProcessDamage bind event target, like before. I need to cast to my character, but then comes the issues of the “object” input.

Does anyone know of a way by which I can cast to my enemy character, and **not** my player character? I’ve tried using an interface, but it seems that’s not the solution to my issue; although, if you do think of a way to properly use interface for this, I’m all for it.

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [July 6, 2017, 11:07pm UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784/2 "2017-07-06T23:07:37Z")

</div>

Make a delegate somewhere easy to reach by everyone like GameMode in my Example. Add Parameters as you like.

> **[Gyazo](https://gyazo.com/3130624791921483f7adc40d503b832e)**
>
> Easily capture screenshots, GIFs, and replays that are ready to share. Download the free app for windows and mac.

In your NPC´s, Characters or whatever at any time dispatch that event like that:

> **[Gyazo](https://gyazo.com/c01900a14ec08aad7687f38f87e75f6f)**
>
> Easily capture screenshots, GIFs, and replays that are ready to share. Download the free app for windows and mac.

And in your Widget Bind to the Event from GameMode (Dont forget to assign your Gamemode properly)

> **[Gyazo](https://gyazo.com/f9ca41a2f195287961ba1728abb77eb3)**
>
> Easily capture screenshots, GIFs, and replays that are ready to share. Download the free app for windows and mac.

Note: You have to bind to a Event just once BeginPlay or EventConstruct is enough. Don´t do it on Tick =)

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [July 6, 2017, 11:09pm UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784/3 "2017-07-06T23:09:58Z")

</div>

And ofcourse “Who” you can Cast to whatever you need or use Interface Calls like “Get Health” you can implement in the Individual Blueprints.

---

<div class="post-metadata">

**Author:** ![Nachtmahr](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nachtmahr](https://forums.unrealengine.com/u/Nachtmahr)\
**Post date:** [July 6, 2017, 11:19pm UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784/4 "2017-07-06T23:19:04Z")

</div>

And a second Answer for good Messure. The more “Proper way” of doing it.

Make a Actor (or other Base Class) Variable in your Widget BP and expose it on Spawn. Let your Individual NPC´s/Players Create the Health Widget (everyone gets one no need for a Massive one who Handles everyone) pass “self” to the Widget. Now your Health Widget knows from who to pull Data from (you simply pass it along).

Preferably you would have a common Base Class for your Character, NPC´s etc or a simple Component that holds Health and other Data you might want. Just pass along where you want to get the Data from.

Good Luck and take a smart approach =)

---

<div class="post-metadata">

**Author:** ![Maladrum](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/maladrum/32/1013148_2.png) [@Maladrum](https://forums.unrealengine.com/u/Maladrum)\
**Post date:** [July 7, 2017, 12:25am UTC](https://forums.unrealengine.com/t/how-can-i-cast-from-a-widget-to-a-non-npc-character/399784/5 "2017-07-07T00:25:24Z")

</div>

This is more than enough information, Nachtmahr, thank you! This solves even more issues for me than just this.
