RepNotify not working?

So I’ve been learning how multiplayer works and I thought I had a decent understanding on how to setup everything and the importances of knowing when to use RPC’s vs RepNotify. I’ve been testing making my character hold items and all seemed fine when I used RPC’s but not when I used RepNotify, I need it to work this way because when the clients runs out of Net culled distance everything isn’t in sync anymore, once the player drops the item it’s in different locations as well as floating in the air when I have coded it to drop the item to the floor. Whereas when I used RPC’s the code for dropping the item works fine instead of floating in the air. So I’m wondering why when I change the code to use RepNotify the code doesn’t work quite the same? Below is links to the code I have setup, if anyone can figure it out it would be a massive headache lifted.

PickUp Item

Inside the RepNotify Variable (the pickup code works all fine)

Drop Item

Inside Drop Item RepNotify variable

RepNotify is executed in the client side… so the server side don’t know what is going on and that is a replication problem.

1-Change the value of the replicated variable on server side
2-Execute whatever function in server side
3-Execute whatever function inside RepNotify (client side)
4-Done!!

1 Like

Thanks for the response, I’m not sure how to execute that properly in my blueprints. Do you happen to know where to point me so I can go and have a look? Everything I happen to find is that they do all the code in the RepNotify and execute it on the server side.

You don’t set Rep_notify variables in the OnRep function.

Server pickup
Is currently holding, do some stuff → Set rep_notify variable

On rep function: Branch (rep_not var): true → do this, False → do something else.

Think of the on rep var as a switch/toggle. When the server changes the value of the var (toggles it) the on rep function is executed. Based on the toggled value you do A or B.


Another key factor when using Rep_notify on actors is you should use a pretty high net cull distance. It should be higher than the actors render cull distance. This ensures that any changes occur prior to the player being able to see them.

For instance If I drop an actor w/physics it should be on the ground well before an approaching “out of range” player gets close enough to see it floating.

1 Like

101

2 Likes

Close!

Server will execute the OnRep function as soon as it sets the value. So no need to call it directly.

Srv → Set var
OnRep Func: Do whatever

2 Likes

But it is executed on client side only

I have a 4 part series on networked doors/elevators that specifically uses a rep_notify enumerator.

Here’s part 2 which gets into the Rep_notify aspects. Should get you on solid ground.

I do it like this in C++

it is the only way it works

//------------------------------------
UPROPERTY(ReplicatedUsing=OnUpdateTeamType)
ETeam TheTeamType = ETeam::None;
//------------------------------------
UFUNCTION(Server,Unreliable)
void SetTeamType(ETeam TeamType);

//------------------------------------

UFUNCTION()
void OnUpdateTeamType();
//------------------------------------

void UMaterialHandlerComponent::SetTeamType_Implementation(ETeam TeamType)
{
	TheTeamType = TeamType;
	SetTeamSkin(TheTeamType);
}
//------------------------------------

void UMaterialHandlerComponent::OnUpdateTeamType()
{
	SetTeamSkin(TheTeamType);
}
//------------------------------------

where are you running this code? It should be in the Game Mode. TeamType should be a playerstate variable. Any skin changes should be handled in the OnRep in the playerstate.

For something like spawn grouping by TeamType, you’d handle that in the GM.

Nope… it is a UActorComponent. i’m using it on my character.

I’m assuming it only has to do with cosmetics then.

If so the Rep_notify var should reside in the PlayerState, so all players and the GameState have a reference to it if needed.

Player State → OnRep_Function gets a reference to the Actor Component and calls the appropriate function.

Easy Peasy

Yes, that is…

I assign the team from GameMode… but I change the skin on the character (it’s where I have access to the mesh).

I’m using the PlayerState for public variables like the Score, the Name, the ID… and the team too… what I want others to know about me.

Nope… I have a Subsystem to handle the teams (UGameInstanceSubsystem derived class)

BP and C++ behave differently regarding RepNotify. With BP the OnRep_Whatever is also called for the server (with exceptions). E.g. if you change elements of an array (with Add node), OnRep won’t be called for BP either.

2 Likes

I am quite confused since I have the situation on 5.3 that rep notify executes on all clients but not on the server. (Blueprints)

I not sure… but maybe they changed the behaviour to be the same as in C++…
if so, just exectute the same function in the server side after changed the value of the replicated variable.

Server RepNotify doesnt occur on Arrays for whatever reason if that helps

2 Likes

@Auran131 I abhor those new bots (I refuse to call them people):

They’ll grab a post from above and re-repost:

…thinking it will somehow legitimise their account so they can keep spamming the APK links that have been popping around for weeks now. It’s not even the spam that I mind, it’s the time I spend reading necroed threads…

2 Likes

is that what it is, i’ve seen a few repeat questions or weird replies but dont understand why’d theyd bother

1 Like

In the olden forums days the very first account post had to be manually mod-approved. The bots have been living under a rock and still think it’s a thing.

Sadly, while the manual approval kept most of the spam at bay, it mostly prevented legitimate users from posting the actual question… :expressionless:

I can only wish the previous system was still in place - flag a post to make it immediately hidden. If the user appeals, mods can restore it. Spammers won’t appeal, though.

but dont understand why’d theyd bother

It’s draining to flag them and it’s draining to realise you’ve been had after typing for a couple of minutes just to find out it’s another what’s up apk…

3 Likes