OnRep_Pawn not firing on Client when it possess' something?

Maybe I don’t understand the OnRep functions, but are they not supposed to fire on everybodies game when somebody possesses another object?

When my Pawn bumps into something else, I call a function on the server to possess the new object. The possession itself works, but OnRep only seems to fire on the Server, not on the corresponding client?

This was caused by calling Possess() on the client, which should only be done on the server. Check the thread here, and the AnswerHub post here for more info.

To answer your question more generally about OnRep_ functions, they are called when a replicated version of a variable comes in over the network and changes from the current value. In the cases of PlayerController, since they only exist on the server and single owning client of that PlayerController (not other clients), it would not occur for everyone.

Here is a link that should help: https://docs.unrealengine.com/latest/INT/Resources/ContentExamples/Networking/1_4/index.html

Hey Zak,

I appear to have found another issue regarding this and finally have a Repro for it! See here: Unreal Engine 4.8 Preview - Announcements and Releases - Unreal Engine Forums

Already replied there but I guess this thread is more on-topic. :stuck_out_tongue: Could it be that you are calling Possess client-side? That could explain why OnRep_Pawn is not called, because the Pawn doesn’t change server-side. Possess should only be called server-side in a multiplayer game.

(From Other Thread) - Nope definitely calling Possess Server-Side. Possess doesn’t allow calls Client Side anymore anyway :slight_smile:

I am having a problem with OnRep_Pawn. It triggers immediately when the game starts, but when I change a client’s pawn later by calling possess on the server, OnRep_Pawn doesn’t get called anymore. I checked the Pawn-variable of the client’s controller on both server and the client itself: it changes to the new pawn correctly. And there is no call to OnRep_Pawn…

You can override ‘SetPawn’ (which is always called), and do your logic there. SetPawn is a lot more reliable I find.

I believe OnRep_Pawn isn’t always called because the pawn might be changed from replication /RPC before it has a chance to fire… wierd, but true.

I see. That function should come with a warning then (broken! don’t use!)… Thanks for the tip! I will try overriding SetPawn then.

It’s not that it’s broken, it’s just that an OnRep function won’t trigger if the value has already changed on the client - which can be the case sometimes.

Hi, you should use / override AcknowledgePossession instead. - Will fire on owner client when pawn possession happens.

Well, if you can’t rely on it being called on clients after calling possess on the server ONLY, then what could it possibly be good for?

Thanks, will try that one as well.

AcknowledgePossession seems to work fine. It only gets triggered on the “owning” machine, not the server (per se), but that’s okay. If there is something server-sided I need to do, I can still put it under Possess. Thanks again.