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"

Client HUD not showing correct values

So I've been scratching my head over this all day today and can't seem to get anywhere. Essentially, I just want to print the Health and ammo for each player on their HUD. The server displays these values correctly, but the client does not.

To begin, both the ammo and health values in the Character C++ file are marked Transient and Replicated. For dealing damage, I'm overriding the Actor::TakeDamage function in my character class, and here's where a lot of my doubts start to creep in. In the function declaration, I haven't marked it as replicated or on server or anything. If I try to do that, I get a compilation error that functions with a return type can't be replicated. Inside the function I do a HasAuthority() check (another doubt - when am I really supposed to use this? Does it only make sense on functions executed on the server? or RPC/multicast functions? What's the deal?).

If I start two instances in the editor, ON THE SERVER : Both the server and the client deal damage and take damage. Updated Health and Ammo values are shown ON THE CLIENT : Both the server and client always have the default health and ammo values. Updated Health and Ammo values do not reflect.

Any suggestions or discussion would be greatly appreciated. Thanks!

Product Version: UE 4.20
more ▼

asked Nov 15 '18 at 09:25 AM in C++ Programming

avatar image

30 1 4 11

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

1 answer: sort voted first

I would just put the health and ammo values in the PlayerState that belongs to the PlayerController, and set those variables to replicated. If the HUD needs to instantly update instead of waiting for relevance or a repnotify, then use multicast to force update.

more ▼

answered Nov 15 '18 at 07:46 PM

avatar image

3.8k 18 20 20

avatar image hussainAbis Nov 16 '18 at 07:03 PM

I did that and it works perfectly. Can't believe I couldn't think of that myself. Thanks for the help! :)

avatar image mightyenigma Nov 19 '18 at 06:50 AM

I'm glad it helped you. Please mark my answer as Accepted so others with the same problem can find it more easily.

(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