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"

Should my character's inventory exist only on the Server?

Hello, i'm doing a multiplayer game and would like to know if i should replicate my inventory to the Autonomous client or it should only exist in the Server? I'm asking this because right now when a client presses Reload i play the reload animation immediately for fast responsiveness and only on the server do i check if there is a next magazine to reload. The problem is if i start reloading on the client and the server comes to the conclusion that there is no more magazines. I can send a StopReload from Server to Client to stop the reloading animation, but that is not the best user experience because he will see part of the animation when the StopReload reaches the client. So to avoid that, should i replicate the inventory on the Autonomous client for him to be able to perform the magazine verification or should i call the Server first and only when the server responds and confirms there is a magazine can i play the reload animation? Thank you.

P.S: Do SimulatedProxy clients need to have the inventory also? or they just play animations?

Product Version: Not Selected
more ▼

asked Oct 29 '14 at 04:39 PM in C++ Programming

avatar image

6k 163 129 305

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

1 answer: sort voted first

Of course you can replicate all of your inventory from client to server. But you cannot change value of those variables on the client side, the objects are critical to gameplay and should be spawned on the server side - this means that they have an authority there. You can read information about how much ammo has left on the client side to avoid RPC ping-pong. Also, if you replicate all of your inventory, you can show all of it's elements in HUD.

If you don't want to replicate all invetory, use this pattern:

  1. Player controller handles input on Client side and makes RPC call to it's authority on server: Reload().

  2. Reload logic on server decides if you have more ammo or not.

  3. Let's say you don't have any ammo, then server can call RPC to your client OnNoAmmo() wich will cause HUD to display "No ammo" message.

  4. On the other hand if you have ammo, you can call RPC to all clients (multicast) that will cause your animation to play, and be visible by others.

As a compromise, you can replicate only a part of your inventory let's say ammount variable for each weapon. You can check it then on client side before calling Reload(). If you have enough ammo, then call Reload() RPC to server and start animation. If you want others to see your reload animation, then server should call multicast RPC.

I Hope it helped.


more ▼

answered Oct 29 '14 at 06:30 PM

avatar image

578 23 15 48

avatar image xlar8or Oct 30 '14 at 10:44 AM

Yes i need to show my HUD with the inventory, so i have to replicate it. If i do the animation client side and then on the server i call the client multicast method to update all other clients, that will also run on the autonomous client that already was animating, how do i prevent him from playing the animation again? Right now the only way i can think of is by doing this:

 void AMyCharacter::ClientReloadMulticast_Implementation()
      if(Role == ROLE_Autonomous) // or if(bIsReloading)
      PlayReloadAnim();    // Executes only on the simulated clients

The simulated clients also don't need to know the inventory and what magazine you have, they just do blindly what the server tells them right?

avatar image mpo Oct 30 '14 at 11:09 AM
  1. I had no case like this, but my first idea is to check ownership of your pawn.

  2. Yes. But they in fact know... if you replicate an actor from server, it would be replicated to all clients.


avatar image xlar8or Oct 30 '14 at 11:22 AM
  1. What do i check the owner with? The autonomous client is not the owner of the pawn so i not sure if on that function i can check that condition like that.

  2. If i set the replication condition to owner only it will not replicate to the simulated clients right?

(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