# Changing a variable from another blueprint

**URL:** <https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 16, 2020, 8:54pm UTC](https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457 "2020-09-16T20:54:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_3547627f1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3547627f1](https://forums.unrealengine.com/u/anonymous_user_3547627f1)\
**Post date:** [September 16, 2020, 8:54pm UTC](https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457/1 "2020-09-16T20:54:00Z")

</div>

I want to decrement a variable(EnemiesAmount) after the NPC(a character) dies. The variable is saved in the EnemySpawner(an actor). I looked into communicating between blueprints but can’t quite wrap my head around this issue

[[Album] imgur.com ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/6/ed695c93d573f9ea9755bfefec49f95941ea50a4.jpeg "imgur.com") ](https://imgur.com/a/PQMVc16)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 16, 2020, 9:35pm UTC](https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457/2 "2020-09-16T21:35:58Z")

</div>

In the blueprint that does the counting (Enemy Spawner) you could:

 ![313885-screenshot-2020-09-16-223206.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/c/0/7c06b0eb0ad0972c7d0890bff3e8407652710b75.jpeg)

* * *

Ideally though, since it’s a _spawner_, it’s safe to assume this is where the enemies are created; instead of the Get All node, you’d actually bind each Enemy’s `onDestroyed` as they spawn and increase the counter by 1.

A preferable method but I might be assuming too much:

 ![313892-screenshot-2020-09-16-223839.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/7/e/67e8e9fd700bc3aaceff71fa9ca0e957175b12a5.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3547627f1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3547627f1](https://forums.unrealengine.com/u/anonymous_user_3547627f1)\
**Post date:** [September 16, 2020, 10:18pm UTC](https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457/3 "2020-09-16T22:18:29Z")

</div>

Thanks for the answer, how would you call the event from the Npc? The actor isn’t overlapping or a child class, so I wouldn’t know where to get the object.

[[Album] imgur.com ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/a/9ea4844ad42e1b48531bd13ddde3aebcfcc549cb.jpeg "imgur.com") ](https://imgur.com/a/3hmWsQk)

The 2nd Solution is how I did the spawner. only going from npc to spawner is the problem.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 16, 2020, 10:28pm UTC](https://forums.unrealengine.com/t/changing-a-variable-from-another-blueprint/471457/4 "2020-09-16T22:28:52Z")

</div>

> Thanks for the answer, how would you  
> call the event from the Npc?

You do not need to, it will be called from within the actor that is being destroyed. The spawner is just picking up that very broadcast. You’re already calling Self → `Destroyed` in the enemy after they’ve received enough damage, right? (in the original image)

By registering the `onDestroyed` event as demonstrated above, you’re asking the Spawner to execute a Custom Event _whenever_ an enemy is destroyed.

No need to cast or worry about references. 🙂 Try it out.

* * *

Actors come with a bunch of _Event Dispatchers_ already, the _onDestroyed_ event is one of them. There are many others and new can be added, too; each can carry any data you desire.
