Set Array Elem on server not working

Hi, I created a dynamic array in C++:

UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Weapon Inventory")
TArray<bool> WeaponInventory;

and I replicated it using DOREPLIFETIME macro. problem is that if I try to set an array element from a Blueprint, I can set it only on client, because on server it doesn’t work. Is this a bug?

I did this on my blueprint:

http://puu.sh/dObHv/8aa64a8806.jpg

Hi ,

I was digging through some older issues and found this one, which looks like it was never answered. I apologize for oversight. Is this still an issue for you? If so, which version of engine are you using? Thanks!

Now with 4.7.1 problem is solved.

Bug fixed with 4.7.1.

Multi-dimensional arrays still doesn’t work.

Hey Azarus-

Which version of engine are you using? Also, can you include how your multi-dimensional array is setup ( code files if you’re doing it through code or a screenshot if it’s setup in blueprints). Please provide as much information as you can to help me reproduce this issue.

Cheers

I’m not sure if this issue/question has been resolved, but I’m running into a similar issue when trying to update a dynamic array from client.

Here’s my scenario. I have a vote system for a multiplayer game. When players are in lobby, they have ability to vote on next map to be played.

In Lobby GameState, I have a dynamic array (LevelListVoteArray) that is built on EventBeginPlay. This information is pulled from list of available levels that we set in GameInstance. array is building properly and is allowing us to update whenever host player, or server, clicks UMG icon for that particular map (also built dynamically based on level list). LevelListVoteArray serves only to hold votes for level, or individual index, that pertains to vote player cast.

Here are events as they occur in timeline:

  1. Lobby_GameState builds LevelListVoteArray (replicated) from list of available levels in GameInstance on EventBeginPlay
  2. UMG_LobbyUI builds list of levels that can be voted on from list of available levels in GameInstance. Each button has an index associated with it that denotes it’s location in level list arrays.
  3. When a player clicks on level they would like to vote on, a function in UMG_LobbyUI called SendVoteToServer gets array index of map player voted on, casts to a function in LobbyGameState called SendVoteToServer. This function calls another event called IncrementNextMapVote which is set to “run on server”. (I tried just pumping information into function that is set as “run on server” from UMG_LobbyUI, but that didn’t work either, so instead, I set up a separate event that runs on from UI, which calls first SendVoteToServer function on client, which in turn runs IncrementNextMapVote on server)

I set up print strings along way which allows me to tell whether or not functions are all being called and everything runs all of way through, it just doesn’t seem to be incrementing votes.

I also set up a text block in UI that lists all of votes that have been cast and set that to pull from LevelListVoteArray that is stored on server, but it’s only updating information when changes are made by Host player.

After scouring forums, it seems as though this was a bug at one point in time, but was fixed with 4.7.1. I am using 4.7.6 and it doesn’t seem to be working still. I thought about moving to 4.8 to see if problem has been fixed or not (I also want to see if server travel issue has been fixed) but I’m not sure as to stability of 4.8, or whether or not 4.8 will be fully implemented at time we plan to publish our game.

Any help you guys can provide would be awesome! Thanks,

Chad

Hey -

I’d like to pose an example to make sure I’m understanding your issue correctly:

Assuming there are four players (player1 is server and player2, 3, and 4 are clients) if all of clients pick mapB and player1 picks mapA then game will load mapA. In next chance to select if all clients pick mapC and player1 picks mapD then game will load into mapD, is that correct?

My first question is what is default state of “HasPlayerVoted” boolean and what events causes value to change? Additionally, using example above, what does each client and server see when people vote (does player1 see player2’s vote as mapB - does player3 see player1’s vote as mapA)?

Looking at your screenshots, in one titled “Function is called in UMG” variable CurrentVoteSelected is being used by SetEnum as target prior to variable itself being set.

Cheers

Hi ,

Thanks for quick response. Using your example, player 1 being server, it’s not updating votes in array for any of players except server.

default state of “HasPlayerVoted” boolean is false, it is set to true first time player presses button to vote, which is picture for “Function is called in UMG”. Right now clients only see vote from server, since their votes don’t update array on server. There is a counter on vote button that pulls information from array on server, so whenever server votes, it updates on all of clients just fine.

I apologize for picture being so small for third picture. node that is target node is a SetEnum for visibility node that is purely for cosmetic purposes. Whenever someone votes, there is a visual cue that tells them whether or not they can vote.That part actually works great. I’ve set up print string nodes along way to see if I could find out where it’s breaking, but it actually makes it all of way to end, it just doesn’t actually update array on server.

Thanks again

Hey ,

Thanks for taking a look at this for me. I figured out what was going on with not updating array in GameState. I was trying to change value of array indices from UMG. Basically I had function being called from UMG, cast to GameState and then trying to update in GameState on server.

Now, way I have it, and it works, is that when you press vote button, it calls a function in UMG that casts to PlayerState and runs a function in PlayerState that updates array in GameState on server.

I’m extremely new to programming (about 3 months in) so I’m not sure if this is actually a bug that you can’t update GameState array from UMG, or if proper way to change array in GameState would be to cast to PlayerState and then run function that resides in GameState. Either way, I’ve got it working, so thanks again for all of your help,

Chad