Netmulticast only called on clients and not server?

Hi,

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;

.CPP

    bool ATestModelCopyPlayerState::OnRep_bIsReady_Validate(bool setReady)
    {
    	return true;
    }
    void ATestModelCopyPlayerState::OnRep_bIsReady_Implementation(bool setReady)
    {
    	OnRep_bIsReady_Imp();
    }

And the blueprint where bIsReady is modified :

Of course I can call the implementation right after that but I would like to know what is wrong.

rXp

That explains it thanks.
The replicatedusing only exec on clients but netmulticast everywhere. Except that both can’t be a property at the same time.

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

SetReady(bool bReady)
{
       bIsReady = bReady;
       OnRep_bIsReady(bIsReady);
}

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).

If you need it called on server too, simply call the function manually after you change the value :slight_smile:

That’s what I did. Thanks :slight_smile:
Now I know :slight_smile: