How to transfer the value of the variable from the server to the client?

Discussions about Coding and Scripting
User avatar
f7r
Experienced
Posts: 104
Joined: Mon Oct 19, 2020 6:53 pm

How to transfer the value of the variable from the server to the client?

Post by f7r »

In EavyDarkmatchIII i have:
mutator class:

Code: Select all

event PreBeginPlay()
{
	if ( !Initialized )
		Spawn(class'EavyDarkmatchSpawnnotify');
	Initialized = True;
}
spawnnotify class:

Code: Select all

class EavyDarkmatchSpawnnotify expands SpawnNotify
	config;

var(EavyDarkmatchIII) globalconfig bool EavyAmbientBrightness;
var(EavyDarkmatchIII) globalconfig bool EavyFogZone;
var(EavyDarkmatchIII) globalconfig bool EavyLensFlare;
var(EavyDarkmatchIII) globalconfig bool EavySkyZone;
var(EavyDarkmatchIII) globalconfig bool EavySpecialLit;
var(EavyDarkmatchIII) globalconfig bool EavyDisabledLight;
The values of the spawnnotify variables are taken from the client config. It is not right. How to make them transmitted from the server config?
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

Store all in mutator class as globalconfig fields. Mutator exists only on server.
Spawn Custom Class with fill fields. This Actor relevant to all client, so transfer to it and replicate it fields.
Last edited by Buggie on Tue Apr 27, 2021 6:13 pm, edited 1 time in total.
User avatar
sektor2111
Godlike
Posts: 6133
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: How to transfer the value of the variable from the server to the client?

Post by sektor2111 »

You need a replication block.
Certain things which I've done here did not worked exactly as I wanted and then I delayed variables... or I missed something needed for replication in initial stage. I ended in replicating this properly but later I made things out of replication -> assigning title based on map's file-name right in client without sending this variable from server, but I could do it using replication too... Look at Actor.uc for figuring replication stuff.
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

Of course fields must be described in replication block.

Here good info about that: https://wiki.beyondunreal.com/Everythin ... id_to_ask)

I only want note very important thing:
NEVER try replicate globalconfig or config variables. This is usually ended with desync this fields.
You need think this things is mutually exclusive.
https://github.com/OldUnreal/UnrealTour ... issues/301
User avatar
sektor2111
Godlike
Posts: 6133
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: How to transfer the value of the variable from the server to the client?

Post by sektor2111 »

It sounds logic to me... this remembers me by those screwed things from Level... The only way to replicate these is... changing them a tiny bit, it's when replication makes sure about new data - perhaps reverting it back shortly... forcing two transmissions.
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

sektor2111 wrote: Tue Apr 27, 2021 6:34 pm The only way to replicate these is... changing them a tiny bit, it's when replication makes sure about new data - perhaps reverting it back shortly... forcing two transmissions.
Wrong. Only way to replicate way - via another field, which not "config".
Because you can not know be replication or not. So you can not rely on it.
You change field, wait 5 seconds and change back. But during this 5 seconds network for this client overloaded, so decided not send your stuff. Hello, desync!
User avatar
f7r
Experienced
Posts: 104
Joined: Mon Oct 19, 2020 6:53 pm

Re: How to transfer the value of the variable from the server to the client?

Post by f7r »

Buggie wrote: Tue Apr 27, 2021 6:08 pm Spawn Custom Class with fill fields.
How to fill fields? Simple example, pls.

EDIT
something like?

Code: Select all

s = Spawn(class'XXX');
if ( s != None )
{
	s.bField = True;
}		
Fields so that they can be visible outside somehow specifically declare?
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

Just set it. Like you do in your example.
But you want set it not to constant.

Code: Select all

var(EavyDarkmatchIII) globalconfig bool bMyField;
var(EavyDarkmatchIII) globalconfig bool bMyField2;

s = Spawn(class'XXX');
if ( s != None )
{
	s.bMyField = bMyField;
	s.bMyField2 = bMyField2;
}

class XXX;
var bool bMyField;
var bool bMyField2;

replication
{
	// Variables the server should send to the client.
	reliable if( Role==ROLE_Authority )
		bMyField, bMyField2;
}

defaultproperties
{
      RemoteRole=ROLE_DumbProxy
      bNetTemporary=True
}
User avatar
f7r
Experienced
Posts: 104
Joined: Mon Oct 19, 2020 6:53 pm

Re: How to transfer the value of the variable from the server to the client?

Post by f7r »

Code: Select all

class EavyDarkmatchSpawnnotify expands SpawnNotify;

var bool EavyAmbientBrightness;
var bool EavyDisabledLight;

replication
{
	// Variables the server should send to the client.
	reliable if( Role==ROLE_Authority )
		EavyAmbientBrightness,  
		EavyDisabledLight;
}

function PostBeginPlay()
{
	local Actor A;
	
	log("EavyAmbientBrightness "@EavyAmbientBrightness);
	log("EavyDisabledLight "@EavyDisabledLight);
	<...>
}	
//==============================================================================
class EavyDarkmatchMutator expands Mutator config;

var(EavyDarkmatchIII) globalconfig bool EavyAmbientBrightness;
var(EavyDarkmatchIII) globalconfig bool EavyDisabledLight;

var bool Initialized;

function PreBeginPlay()
{
	local EavyDarkmatchSpawnnotify s;
	if ( !Initialized )
	{	
		s = Spawn(class'EavyDarkmatchSpawnnotify');
		if ( s != None )
		{
			s.EavyAmbientBrightness = EavyAmbientBrightness;
			log("___EavyAmbientBrightness "@EavyAmbientBrightness);
			s.EavyDisabledLight = EavyDisabledLight;
			log("___EavyDisabledLight "@EavyDisabledLight);
		}		
	}
	Initialized = True;
}
defaultproperties
{
      EavyAmbientBrightness=False
      EavyDisabledLight=True
}	
in server ini

Code: Select all

EavyAmbientBrightness=True
EavyDisabledLight=False  
in server log

Code: Select all

EavyAmbientBrightness  False
EavyDisabledLight  True
___EavyAmbientBrightness  True
___EavyDisabledLight  False
What's wrong? :noidea
1 PostBeginPlay() from class EavyDarkmatchSpawnnotify runs before PreBeginPlay() from mutator class?
2 Why value variables in class spawnnotify is taken from defaultproperties, and not from server ini?
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

Because PostBeginPlay called during Spawn chain sequence, so before you set this values.

Read it: https://wiki.beyondunreal.com/What_happ ... is_spawned
User avatar
f7r
Experienced
Posts: 104
Joined: Mon Oct 19, 2020 6:53 pm

Re: How to transfer the value of the variable from the server to the client?

Post by f7r »

Ok. My question #1 I understood. About Spawn chain sequence. Thank you Buggie.
Then it is impossible to make logic on replicated variables in event of this sequence? What should I use in this?
And #2 - it is not clear why internal variables of class EavyDarkmatchSpawnnotify accepted the values of defaultproperties class mutator? But how did it get there?

EDIT

Maybe it is better to somehow read the mutator variables from the inside of EavyDarkmatchSpawnnotify spawned on client?
User avatar
sektor2111
Godlike
Posts: 6133
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: How to transfer the value of the variable from the server to the client?

Post by sektor2111 »

Buggie wrote: Tue Apr 27, 2021 7:01 pm
sektor2111 wrote: Tue Apr 27, 2021 6:34 pm The only way to replicate these is... changing them a tiny bit, it's when replication makes sure about new data - perhaps reverting it back shortly... forcing two transmissions.
Wrong. Only way to replicate.... this 5 seconds network for this client overloaded, so decided not send your stuff. Hello, desync!
Mmm... perhaps in 5 seconds there is nothing going evil. Think at game speed. Admin can change this and client says: Faster. Admin: Okay, faster. Again: Faster please ! Admin: Okay it's faster. These are working.
As a matter of fact, in a heavy navigation work during run-time I put down game-speed until a new network was rebuild. Then I put game back to previous speed. No desync and nothing occurred. By the way, gamespeed is configurable and replicated. Problem comes when TimeDilation is screwed in map and... game has Classic settings speed 1.0. Nothing is changed because speed is "class.default" and client stays screwed figuring lousy moves.
I solved problem in MonsterHunt by assigning in server a "class.default" lower speed (around 0.9999...). When game has adjusted speed to 1.000000, value was sent to client because it was not a "Class.Default" speed, enforcing client to change from value screwed to 5 into value 1 matching server's speed. I wasted 2 days in that time for figuring what I have to do... and yes, by the way, MonsterHunt needs this fix too if server uses Classic Level and normal speed or else game goes into crap for client.
And then... here I've learned a bit what does replication and when but not everything. Replication works when values are changed and not game's default, but... it depends on the moment when are checked. They need time to reach in client and so a PostBeginPlay check in client won't show anything unless we are talking about bNetInitial or such... You can imagine what's going on at 500 ms ping and why such "clients" should be rejected...
To not forget Monster/Player/Bot animations how often are changed - replicated - and, excuse me but I don't get what desync happens there as long as these might change really fast and all related data (Health, Velocity, Lightning (TriggerLight in stage), etc.) Let me know where is the desync here. If you talk about overloading those 1023 channels (okay 1024) that's another story. Good luck with maps having 5000 Actors using replication...
Buggie
Godlike
Posts: 1921
Joined: Sat Mar 21, 2020 5:32 am

Re: How to transfer the value of the variable from the server to the client?

Post by Buggie »

I talk about proper way do things.
If things work to you this is not necessary mean it make in proper way.
Possible it only work for your conditions only or you not notice when it fail.

Therac-25 is too work most time fine.

--- EDIT ---
f7r wrote: Wed Apr 28, 2021 1:25 am Then it is impossible to make logic on replicated variables in event of this sequence? What should I use in this?
I not see any stuff about client in your post. You check server log. IDK why.
No "simulated" keyword near calls.

Possible you need better understand difference between client and server and how replication work.

About where you can call your code on client:
Possible you need PostNetBeginPlay event.
On server it will be called during spawn with defaults but on client, possible, with replicated values. Need check it.
f7r wrote: Wed Apr 28, 2021 1:25 am And #2 - it is not clear why internal variables of class EavyDarkmatchSpawnnotify accepted the values of defaultproperties class mutator? But how did it get there?
It is strange. In my assumption there must be default values from class itself ("false" if you not touch it).
f7r wrote: Wed Apr 28, 2021 1:25 am Maybe it is better to somehow read the mutator variables from the inside of EavyDarkmatchSpawnnotify spawned on client?
Mutator not exists on client normally.
You can send it via enable it for replication.
In general no any difference with current way.
But you can not be sure if mutator already replicated on client.
UE guaranteed only sequence of one actor calls/changes. And only if it is "reliable" replication stuff.
If you use more than one actor, then order of spawn Actors on client not determined.

Also I see
f7r wrote: Wed Apr 28, 2021 12:47 am if ( !Initialized )
In your code, so or you blindly copy that code or you can be familiar with concept "run once" code.
So you can use this approach for run some code once on first Tick or when all stuff replicated to client fully.
User avatar
f7r
Experienced
Posts: 104
Joined: Mon Oct 19, 2020 6:53 pm

Re: How to transfer the value of the variable from the server to the client?

Post by f7r »

So... There is a mutator. It has config variables. It will spawn class (spawnnotify). I want to pass into client (and server maybe too) instance class the values of these variables. To use these values in the workflow of class spawn (if it posssible at all). How to do it right way?
ShaiHulud
Adept
Posts: 446
Joined: Sat Dec 22, 2012 6:37 am

Re: How to transfer the value of the variable from the server to the client?

Post by ShaiHulud »

It is possible (though can't promise this is the right way). Have a look at the classes inside of this zip file from a HUD mutator I put together a while ago - specifically the variables:

giBeaconDisplayStyle
giREPBeaconDisplayStyle
gbClientSideBeaconStyleSet
giClientSideBeaconStyle

...inside of the HUD_Beacon class. It's been a while since I did any uscript, but I see a note in this unit file which says

Code: Select all

//-----------------------------------------------------------------------------
simulated function PostBeginPlay()
{
  // Server-side -> avoid problems with replicating class default properties
  if (Role == Role_Authority)
    giREPBeaconDisplayStyle = giBeaconDisplayStyle;

  Super.PostBeginPlay();
}
I can't remember what this "problem" is, but I vaguely remember finding details about it somewhere at the time - probably in the Unreal Wiki