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:
In my HUD graph I made a custom event:
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 ?
1- “I will remove a life” gets printed?
2- HUD ref is valid?
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.
If it compiles, it doesn’t mean a variable is valid.
Anyway, about the question number 1?
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:
- Get Player Controller (at needed index, 0 will be current player even for multiplayer games)
- cast it to you custom player controller (if you have it)
- get access to Lives Var of that controller, just draw out cord from player controller reference, disable context sensetivity and write “Get Lives Var”.
My lives var is in my HUD widget blueprint. I need all players to share the lives.
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
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?
move it to gamestate, what is that ?
do you mean the level blueprint ?
bluprint based on gamestate class in blurprint folder
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
im not sure what you mean by putting lives counter there
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
***** 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)
ah so you mean I should store the actual variabls in gamestate and call them from my hud etc