In my custom PlayerState I created a variable bIsReady and replicated it. It should also call a function (OnRep_bIsReady) when replicated.
The function works but is only called on clients and NEVER on the server. Why and How ??
.H
UFUNCTION(BlueprintImplementableEvent, meta = (DisplayName = “call when ready state changes”))
virtual void OnRep_bIsReady_Imp();
UFUNCTION(reliable, NetMulticast, WithValidation)
void OnRep_bIsReady(bool setReady);
/** is the player ready ? */
UPROPERTY(ReplicatedUsing = OnRep_bIsReady, EditAnywhere, BlueprintReadWrite, Category = PlayerState)
bool bIsReady;
When you use Notify, it will call the OnRep function on all client. Also with NetMulticast _Implementation function will be execute in all client. From what i see you either need ReplicatedUsing or NetMulticast only.
ReplicatedUsing will call OnRep_bIsReady on all client not server, and with NetMulticast, if you call OnRep_bIsReady on the server it will execute OnRep_bIsReady_Implementation on all client not server.
Why is it not run on server ? That the way how network is designed for most of engine. Any RPC call or communication will always work 1 way either from client to server or server to client. Because if you also call this on server if you set same replicated value or call the NetMulticast in the implementation again it will be a loop and flood the server.
My suggestion is remove NetMulticast, because ReplicatedUsing already do the same thing, the make a function call SetReady(bool bIsReady), inside you can do this
When you call this on Server, it will set the bIsReady it will call OnRep_bIsReady on all client, and you also call OnRep_bIsReady so it will execute on server also.
NOTE: this rep will only call if they detect the different between previous value if you want to notify all time, use this DOREPLIFETIME_CONDITION_NOTIFY(ATestModelCopyPlayerState, bIsReady, COND_None, REPNOTIFY_Always). If not just use the normal DOREPLIFETIME(ATestModelCopyPlayerState, bIsReady).