x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Where should I store my Health Value!

Hey guys simple question!

Where should I store my character stats, like health, amount of lives and items collected.

The player can died and respawn, so holding them in the character is a bad idea, I was thinking the player controller is that correct? because if they die controller does not get deleted.

Thanks!

Product Version: UE 4.10
Tags:
more ▼

asked Feb 10 '16 at 05:40 PM in Blueprint Scripting

avatar image

rfw7755
36 3 5 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

It always depends on your needs. In most cases, the Pawn is suitable.

If you are going to develop for multiplayer, you have to consider whether other people should know of your health. The PlayerState is automatically created per player and is replicated between players.
The Controller is a bad idea if you want to have multiple pawns. If you store the health in your controller and you want to change pawns. The Pawns will have a shared health then.

I for myself prefer PlayerState. and use the Mode to decide what happens in certain circumstances. For example I have a Health and Air Value in my PlayerState. The GameMode checks if my Pawn is underwater. If it is, the Air is reduced. If the Air reaches 0, the Health decreases,too.

more ▼

answered Feb 11 '17 at 09:00 PM

avatar image

Raildex_
512 18 37 62

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi,

You are free to store it anywhere you like, you always need to consider the game you are making. In your case, I would personally store it in the Player State. It is replicated, so it can function in multiplayer too, and it consists for the whole game, but keep in mind that loading a new level will reset the values in it.

more ▼

answered Feb 10 '16 at 05:52 PM

avatar image

Kontur
191 6 12 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
more ▼

answered Feb 11 '17 at 01:37 PM

avatar image

TCibils
26 3 5 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Store them in the character it's easier to manage, just don't destroy that character when it dies. Just remove life or drop the items.

You're the one that has to decide what happens to the character when health reaches 0, it doesn't mean you have to destroy that character, just set its location somewhere.

more ▼

answered Feb 13 '17 at 05:09 AM

avatar image

kurosu143
349 11 14 21

avatar image G1K777 Aug 25 '18 at 12:46 PM

Add a "death animation" create a delay... then spawn it after clicking (OK) in the town or something :) Destroying it means basicly you legit destroy it like mobs where you don't want to use that mob anymore.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question