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"

Reading Variable From Gamemode As a Client

A project of mine uses a Gamemode class to base logic where enemies spawn in waves, which has an integer variable called CurrentWave.

All players have a HUD that displays the current wave, however, I've had difficulties replicating the integer variable from the Gamemode to the client. From what I've read, Gamemodes only exist on the server, thus calling RPCS or replicating variables wouldn't change anything apart from itself.

I've tried using a for-loop on the Gamemode per tick to loop through all existing PlayerControllers, then setting another replicated integer variable on that, so it would (hopefully) replicate to the client and could be read by the HUD, but it only just works on the server and not the client.

I am ears open to anyone who can correct me since my understanding on networking is fragile.

Product Version: UE 4.20
Tags:
more ▼

asked Jan 31 '19 at 08:01 AM in C++ Programming

avatar image

gamnuke
3 1 3

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I believe the easiest (and the clearest) solution would be to store CurrentWave in GameState instead. As it lives on both server and client, your GameMode can work with it, while clients can access it, without manual hassles.

more ▼

answered Jan 31 '19 at 09:36 AM

avatar image

KristofMorva
1k 4 5 7

(comments are locked)
10|2000 characters needed characters left

I've actually used the Gamestate before trying out the PlayerController, until I decided to give it another go, then realising that the variable in GameState never replicated. I forgot to mention that the int CurrentWave was in a replicated struct, in which I also forgot to add UPROPERTY() on top of each variable. Now it works fine :)

more ▼

answered Jan 31 '19 at 11:56 AM

avatar image

gamnuke
3 1 3

(comments are locked)
10|2000 characters needed characters left
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