# Reducing my lives doesn't work by function or custom event

**URL:** <https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532>\
**Category:** UI\
**Tags:** hud, calling-a-function, unreal-engine, Blueprint, question\
**Created:** [June 30, 2015, 8:36am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532 "2015-06-30T08:36:55Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [June 30, 2015, 8:36am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/1 "2015-06-30T08:36:55Z")

</div>

So when an AI gets to my target location, it calls a function that is on my HUD, I also tried using a custom event - the event and function both says to take 1 life off in my HUD.

In my HUD I made a function:

[http://i.imgur.com/i5FOPiN.png](http://i.imgur.com/i5FOPiN.png)

In my HUD graph I made a custom event:

[http://i.imgur.com/A4HQMy1.png](http://i.imgur.com/A4HQMy1.png)

And I guess this is where it’s going wrong; in my targetlocation is where I trigger both the event and function, maybe I am not doing it right ?

[http://i.imgur.com/xsuFmNI.png](http://i.imgur.com/xsuFmNI.png)

---

<div class="post-metadata">

**Author:** ![zamy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zamy](https://forums.unrealengine.com/u/zamy)\
**Post date:** [June 30, 2015, 9:01am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/2 "2015-06-30T09:01:24Z")

</div>

1- “I will remove a life” gets printed?  
2- HUD ref is valid?

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [June 30, 2015, 9:34am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/3 "2015-06-30T09:34:16Z")

</div>

it is valid, it compiles with a tick, the hud reference is a variable with my hud selected - the hud is where my lives number is.

---

<div class="post-metadata">

**Author:** ![zamy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zamy](https://forums.unrealengine.com/u/zamy)\
**Post date:** [June 30, 2015, 10:01am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/4 "2015-06-30T10:01:01Z")

</div>

If it compiles, it doesn’t mean a variable is valid.  
Anyway, about the question number 1?

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [June 30, 2015, 10:35am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/5 "2015-06-30T10:35:50Z")

</div>

Hi,

where is your Lives var stored? If this is per player variable, then i recommend store it in player controller bluprint, since there should be only 1 player controller per player. Then in your HUD function “Remove a Life” you can do this:

1. Get Player Controller (at needed index, 0 will be current player even for multiplayer games)
2. cast it to you custom player controller (if you have it)
3. get access to Lives Var of that controller, just draw out cord from player controller reference, disable context sensetivity and write “Get Lives Var”.

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [June 30, 2015, 6:20pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/6 "2015-06-30T18:20:46Z")

</div>

yes the text does print

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [June 30, 2015, 6:32pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/7 "2015-06-30T18:32:15Z")

</div>

My lives var is in my HUD widget blueprint. I need all players to share the lives.

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [June 30, 2015, 7:46pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/8 "2015-06-30T19:46:19Z")

</div>

seems this is the problem, because every user in multiplayer will have his own HUD widget and his own variable, so try move it to gamestate because seems only one exist per type and game

---

<div class="post-metadata">

**Author:** ![zamy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zamy](https://forums.unrealengine.com/u/zamy)\
**Post date:** [July 1, 2015, 11:28am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/9 "2015-07-01T11:28:04Z")

</div>

yep that value it’s more fitted for the gamestate.  
Anyway, try to print the “HUD ref” value. Can you show where you set it too?

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 1, 2015, 3:58pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/10 "2015-07-01T15:58:10Z")

</div>

move it to gamestate, what is that ?

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [July 2, 2015, 11:31am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/11 "2015-07-02T11:31:55Z")

</div>

bluprint based on gamestate class in blurprint folder

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 2, 2015, 12:15pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/12 "2015-07-02T12:15:05Z")

</div>

do you mean the level blueprint ?

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 4, 2015, 1:18pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/13 "2015-07-04T13:18:45Z")

</div>

please can you tell me

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [July 5, 2015, 8:40pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/14 "2015-07-05T20:40:57Z")

</div>

GameMode class, for example when you open Third Person Template there’s standart blueprint ThirdPersonGameMode and this is exist only as 1 instance per level i think, better place you lives counter here because you can simply get access to current game mode

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 5, 2015, 9:45pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/15 "2015-07-05T21:45:58Z")

</div>

im not sure what you mean by putting lives counter there

---

<div class="post-metadata">

**Author:** ![happyhorror\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@happyhorror\_1](https://forums.unrealengine.com/u/happyhorror_1)\
**Post date:** [July 5, 2015, 10:42pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/16 "2015-07-05T22:42:06Z")

</div>

you told your counter in HUD blueprint, but every player have his own HUD and probably you can’t get reference to client’s hud also every player will have his own counter in this way

The idea i trying give you is just a code design following next rules:

\*\*\*\*\* if you need store anything related to whole game and not to every playr, better place would the class that exist only as single instance and accessible simply from everywhere, example values

total player lives (your variable), game pause state wave number and so on

better store all these in GameMode blueprint or level blueprint, here is screenshot of third person template and it’s default GameMode blueprint, note that you can create your own blueprint based on GameMode class and assign it as default in project settings

 ![49209-2015-07-06+01-35-11+скриншот+экрана.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/e/ede55e2e8cbdb141ba47965866f73527acb21246.png)

\*\*\*\*\* if you need to store something related to player better place would the class that is player related, it’s PlayerController, example values

player’s lives (not unit’s, but whole lives for player like in TD games), player’s inventory size (for RPG style games), player’s level (for RPG and MMO style games)

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 7:29am UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/17 "2015-07-06T07:29:17Z")

</div>

ah so you mean I should store the actual variabls in gamestate and call them from my hud etc

---

<div class="post-metadata">

**Author:** ![Dannyk90](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dannyk90](https://forums.unrealengine.com/u/Dannyk90)\
**Post date:** [July 6, 2015, 12:22pm UTC](https://forums.unrealengine.com/t/reducing-my-lives-doesnt-work-by-function-or-custom-event/323532/18 "2015-07-06T12:22:01Z")

</div>

YESS IT WORKS, YES 😃
