Replicate On Server But not on Client

Hello!

So i ran into a problem in replicating. As i just started i’m not such a pro. And yes i watched the video’s from unreal engine to get started ^^

Well the problem is that i cannot modify an array from the client, but i can from the server.
If i do it on the client nothing happens, if i do it on the server it gets updated to the client and server.

Now it’s an array which users have to be able to alter, not hackingway, but only through event.

Am i doing something wrong(probably am.)
Here i try to add an item to the array. Bp is replicated, AddItemTolist is “RunOnServer” and global is “replicated”

Here i just try to let it change it.

Anyone that can help?

Greetings,
Celeste

  • Add Item To List
  • Target is Merchant Core
  • Replicated to Server (if owning client)

Pay attention to “if owning client” on screen. Client can call “Add Item To List” on server ONLY if client own that “Merchant Core”. There are any Merchant Core in your scene owned by client?

If you create some actor on server and replicate it to client - both version (server and client’s copy) owned by server.

If you need some object owned by client - there are some:

  1. Each player controller owned by
    every player (usually one on server
    and one on each client)
  2. Pawn or character possessed by
    client - owned by client
  3. One of Player State owned by client
    (close to player controller)

If you want change any datas from client inside server’s owned actors - you need any client’s owned actor as a proxy, like:

  1. Client ask his player state change
    some datas on server
  2. Player state call server version of
    function
  3. Server version of func made any change you
    need

Hey there!

No MerchantCore is just a blueprints connecting all the other blueprints and generally takes care of it all.

Basically it controls all data owned by server, so server owns that actor and clients need to be able to alter variables and arrays in a way they can “update” lists and “add” and “remove” etc.

So if i want my client to add items to the “global” i need to call a server event with data from the client?
How exactly would i do that. I see you wrote proxy but i’m really unsure how to do that.

greetings,
Celeste

UE4 use a server autocrative model so it does not allow client change data on server as easy as you expect. Client can RPC inside some actor only if client own that actor. So model is:

  1. Client RPC (ask do some actions)
    server inside actor this clients
    own.
  2. That server side actor owned by
    client being local on server can do
    any changes (global changes too)

You can use any client owned actor as a proxy. It can be: PlayerController, Pawn, Character or PlayerState.

Just move your event “Add Item To List” from MerchantCore to PlayerState (or PlayerController forexample) and all must work as expected.

Example with playercontroller (i think playerstate is optimal for proxy, but pc is simpler (because pc always exist in any project)):

  1. Add event “Add Item To List” to PC
    graph and set it a “server side”
    like you do before
  2. Call event on a client side (any
    place you need)
  3. PC is a client own so it have
    permisions and call same event on a
    server side PC original and that event do
    any needed changes on server
  4. All changes replicate back to
    clients

I think better to do it inside PlayerState instead PC. PlayerState specially created to place any replicated client owned datas.

P.S. Best location to place any server global datas - GameMode. Its can be easy accessed by “GetGameMode” (without slow “GetAllActorOfClass” and cycles)

  • GameMode - server global datas you
    need to hide from clients
  • GameState - server global datas you
    want to replicate to client
  • PlayerState - datas of each client
    inside client’s own instance of class

Hmm well i got this to work, i can succesfully add data to alll clients.

Now the new struggle is that for some reason my data retrieved from Client-side UMG widget can’t be passed on the Server.

I tried to make a random variable and change the variable in a “run on server” event which works…

Then i tried the exact same with the data from the UMG widget and it doesn’t do it. The UMG widget data is replicated.

So issue is as following:
Get data from umg, output in string(works and get right data), then set “bid var” and etc etc. then i see what bid var is and it’s instant 0 instead of fetched data.
Now then i go to “runerver” to run on server, and the data in “bidvar” is 0 but the “new param 3” stays 2000.

No idea what i’m doing wrong.