ReplicatedUsing with arguments | ShooterGame | EpicStaff help?

In the ShooterGame example, when the current weapon is replicated, the notification method is using an argument.



	UPROPERTY(Transient, ReplicatedUsing=OnRep_CurrentWeapon)
	class AShooterWeapon* CurrentWeapon;

	UFUNCTION()
	void OnRep_CurrentWeapon(class AShooterWeapon* LastWeapon);


Where is LastWeapon comming from?
Does the engine pass the “previous” value of the replicated value and are there any other undocumented parameters?

1 Like

Uh, good question. Can i up vote that? :smiley:
I worked a couple of days with the ShooterGame example but it seems like i missed that OnRep.
I thought OnReps can’t have any parameters, since you don’t actually call them by hand, so you
can pass something :X

Wow, please let this be true!

I’m interested in knowing that also as for me the replicated function do not have any parameters.

I’m pretty sure you can’t pass Parameters as part of OnRep functions… I’ve never seen that in ShooterGame… where about is it?!

Actually I’ve just realised, you can specify ‘OnRep’ for any replicated variable, BUT you can also call it from elsewhere in the code. It might be that OnRep_CurrentWeapon is actually called manually somewhere as well with the parameters. I’ll have a look in a bit.

I already searched the whole project and i was not able to find any manual call. It is only called through the OnRep logic
when the Server changes the current weapon. I was also sure, that you get an error if you give the OnRep a parameter,
but even this seems to be wrong.

Hey it seems that you were right “If you want the old value, you can add the value as a parameter to the rep notify, and it will pass the old value in that case.”

2 Likes

Well… how about that!

Awesome. Now it would be nice to know if this is possible in Blueprints too :smiley:

I don’t think it’s possible since the functions OnRep created automatically has no inputs and you can’t had any, but it’s easy to create another variable that holds the old value.

I know this might be late but if anyone faced this problem in the future, you can pass to the OnRep function a parameter of the same type of the value being replicated under this function, and it will automatically pass the old value of this variable.