Networking: When To Use What (also how to make a FPS inventory for multiplayer)

I’m a C++ programmer trying to get a full grasp on Networking in Unreal Engine.

What I Know
I’ve completed the official Multiplayer Quick Start from the documentation.
I understand the concepts and rules of Actor Replication.
I understand how to replicate a variable, and how to set up a RepNotify.
I understand how to set up an RPC, as well as the different types.
I understand the general concepts of Relevance and Priority.

What I’m Asking
What I’m still lost on is how I should put those things together into a working game.
As in, what variables of an Actor should replicate? What should the flow of RPCs and non-RPCs be?
As an example, I’m not necessarily looking for an answer to “How do RPCs work?”, but rather “Why/When should I use an RPC?” and “When should variables be set to replicate?”.

What I’m Working On
I’m putting details about my current project/problem here, in case it’s useful.

In my current project, I’m trying to get a FPS weapon system multiplayer-compatible.

I have a ShooterCharacter that has an WeaponInventoryComponent attached. I have a WeaponActor class. All of these classes have replication enabled. The WeaponInventoryComponent handles what WeaponActors the character has, and which one is currently equipped. Information on how to make this setup network-compatible would also be appreciated.

Currently, when I run as a Listen Server, a “server” player can obtain and equip weapons as intended. However, “client” players are unable to equip weapons. Client players fail to equip them because their Casts to EnhancedInputComponent and EnhancedInputLocalPlayerSubsystem fail. Currently, these casts happen in a Client RPC in the WeaponActor class.

All actions you want other players to see must be done by the server.

Equipping a weapon…
Client RPC’s server → Server equips, then Multicasts a sim only equip event.

Read up on Local/Remote Roles. These help you control which proxy can/cannot execute code.

1 Like

Client RPC’s server → Server equips, then Multicasts a sim only equip event.

Apologies, but I could use some clarification. What does “Client RPC’s server” mean? What does “sim only” mean?

Are you saying that, when a character wants to equip, I should check if they’re a proxy, and if so, call a Server RPC that then calls a sim-only Multicast RPC?

Client RPC’s are Events that are set to “Run on Server”.

Example…

Equip Key pressed → Switch has authority (Remote) → Srv Equip Weapon

Srv Equip Weapon (run on server event) → Equip weapon logic

If your weapons are set to “Replicate”, then multicasting isn’t needed.


A multiplayer game consists of 3 pawn proxies.

Authoritative Proxy: Servers version of every player (client connected).
Autonomous Proxy: The clients character that’s controlled.
Simulated Proxy: Copy of your character on other clients simulation.


Sim only means you only have the simulated proxy of the owning client run specific logic.

Say I do something locally. All the sims of my character running on other clients should do the same thing.

For example equipping a weapon usually has an animation played (montage) for the visual equipping part. There also maybe sound fx played.

You would use a Multicast on the server to execute that event on all clients. Yet you do not want the “Owning client” to rerun logic it has usually already done. So you use local/remote roles on a branch to prevent the owner from running the code. The owner is Autonomous.

I’ve implemented what you’ve given, but Casting the player controller’s input component (to an enhanced input one) still fails on clients. What do you know about Enhanced Input? Should I be messing with a player’s InputMappingContexts on the server or the client?

Not sure why you are casting to the input mapping context in the first place.

I’m not. I’m casting to EnhancedInputComponent. That allows for the editing of InputActions and InputMappingContexts to a Pawn.

I don’t see the relation to FPS Multiplayer Inventory. There’s no reason to modify input actions.

Figured it out.
I was doing a couple things wrong. The big thing was the fact that I was not using the preferred method of using RepNotifies. This led to the EnhancedInput functions being called on the wrong machines, which is why their casts were failing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.