I was just wondering how to get my inventory to replicate.
Basically, I have an item called MASTER ITEM in my world.
I can pick it up on both the client and the server but when I open the inventory it only shows the MASTER ITEM on the server in the inventory and when I open the inventory on the client there is no MASTER ITEM. how can I make sure My Inventory is updated on the server and the client showing items I picked up on both.
what is the masteritem? ie struct/object/actor?
if you’re new to replication this could be a big topic.
It’s a actor. I am new to unreal just been playing around with it for awhile not really sure how the replication works
Replication is a Server → Client process. Actions on the client do not replicate up.
Outside of general movement, actions that effect world game play need to happen on the server.
e.g. Doors, Loot management (Add, Drop, Use), Health, Stamina etc.
Client inputs the action. Client checks if it would be applicable locally. If so, RPC the server and have it check, then do.
For inventory you want the server to pickup and add the item to inventory.
Inventory actor needs to be set to replicates.
Inventory variables need to set to replicates.
Here’s some general flow logic for networked interaction.
Most setups will require input from the client to interact (press a key). Note Both the Input (Client side) and the Server Event call the same function.
The function uses flow control logic to navigate execution.
Client executes a trace to determine if there is something to interact with.
If So (Branch: True → SHA: Remote) we RPC the server to run the same function.
We are only sending an RPC if there’s something for the server to do. we do not Flood the network with pointless RPC’s which is bad for multiplayer.
Server executes a trace to determine if there is something to interact with.
If So (Branch: True → SHA: Authority), what type of thing did it interact with?
This is where we can use a Switch or other flow control to call a specific function/event/interface for the given type.
Here’s a more flushed out interaction setup.
The interaction Type is used to called specialized functions.
Srv Pickup Item eventually flows out to another switch that handles loot types.
My Add/Remove process and inventory structure is based on my games needs. Not all inventories are alike.
Simple data items are stored in a struct as… simple data. They are added and remove easily.
Complex Items such as weapons (Actors) require a bit more. For example a weapon needs a dedicated Actor Obj Ref. Adding it is having the server spawn the weapon class, attach the actor, update multiple character states, stance, movement speed, animations etc. Setting the Inventory is easy…just set a variable for the given slot.
I know this is a lot, but it’s all relative to the subject.