• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Some way to replicate from Client to Server

Hi,
I wrote mutator WeaponConfig with GUI.
Game admin send in console "mutate weaponconfig menu"
Then Mutator open for that playercontroller some GUI menu with weapon settings.
2012-12-07_164351.jpg


Player change some settings in this menu (client side), then press OK and some long string with settings that player made must be sent to server.

How to to this? I read that Client to Server replication works only for PlayerController->Pawn variables. But I use separete mutator this values have no relation to Pawn values so Client to Server replication wont work.

Now I use some bad hack: when menuclosed I call on client GUIMenu.PlayerOwner().ConsoleCommand(mutate$"some loong string with parameters")
this is bad solution. + I found new bug because of console command string length limitation. Shure I can make routine for few mutate calls but I feel that this is bad solution
 
Last edited:
Don't make a single long string, but send variables one-by-one, e.g. as "key=value" string. The it will work even with your console/mutate method.

hi Poosh. key=value bad desigion cause im already have working mechanism with your LongStringReplication class. So if no other methods instead of mutate command, I will send strings to mutate by chunks. But I not shure If chunks will be received in order :(

This is very bad if whole Unreal Engine have no instruments for replication from client to server. and need to use so gay hacks like console commands. very bad.
 
Last edited:
Upvote 0
It replicates from authority to client, so simply make a class that the client has authority over.
Hi, Benjamin. This mutator use your Weapon Stats grabber routines mirrored not only to Get but to Set values too.

about my question
can you give some code please?

1. the code of replication class
if i spawn it on server so need to somehow set RemoteRole = ROLE_Authority?? but I read that it is unreal to set Client as ROLE_Authority on class that was spawned on server side.. server always be authority.

2. so i think that need to spawn this class on client side? but server must know about it too? so the server role will be role< role_authority. How to spawn class on server side? If I cant replicate values from client to server so i cant replicate Spawns from client to server too? so this replication class will spawn only on client side...

can you give please some code examples. Examples of class itself and usage of this class.
 
Last edited:
Upvote 0
aha, got it
In Unreal Engine 1 there was also the possibility to replicate variables from the client owning the actor to the server, but that feature has been dropped in favor of sending the values via replicated function calls. (We'll see about that one later.)
so Client to Server replication works only if class Owner == Client.PlayerController and only for function calls, not values.

----
UPD.

IT WORKS!!!!!!
2012-12-08_022309.jpg


SO ALL YOU NEED TO KNOW ABOUT replication of values from client to server:

1. make DataTransferClass that extends ReplicationInfo
MyRepInfo extends ReplicationInfo
var string TransferToServer;

2. Because variables cannot be transfered to server, only function calls and it parameters can be transferred, you cant use statements like
DataTransferClass.TransferToServer = "my string from client";
you need to use
DataTransferClass.SetStringFunction("my string from client");
and add that function to replication statement:

replication {
reliable if (ROLE != ROLE_Authority)
SetStringFunction;
}

3. on some serversidefunction Spawn this class and setowner PlayerController that will change values of this class.
 
Upvote 0