From reading the docs I was under the impression that I have to set bReplicates = true of a component to true in order to send RPCs from it. But could it be that I only need to set it to true if I want to replicate properties, but for RPCs it’s enough that the actor is set to Replicates = true?
If the component is stably-named (i.e, it’s a default subobject of the actor and not created at runtime) - then yes you can send RPC’s to/from that component without it needing to be replicated, so long as the parent actor is replicated.
Note that for components, you should do the following in the constructor:
SetIsReplicatedByDefault(true);
Whereas for actors, you should set the property directly:
bReplicates = true;
The reasoning behind it is silly - but it’s a lesser-known evil.
Thanks for your answer!
But in my case I would actually use SetIsReplicatedByDefault(false);
then because I don’t want it to be replicated, right?
In my case I am deactivating/activating this component on the client slightly different than on the server, so I don’t want the replication of bIsActive
to happen, but I still want to send RPCs.
I hope this is not something “crazy” to do, is it?
That’s fine - don’t forget you can also always just disable property replication on certain properties too, like so:
void UMyComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
// Disable Unused Properties (Always active + always replicated)
DISABLE_REPLICATED_PRIVATE_PROPERTY(UActorComponent, bIsActive);
DISABLE_REPLICATED_PRIVATE_PROPERTY(UActorComponent, bReplicates);
}
Oh, I did not know that thank you!
Then, dose “CharacterMovementComponent” need to deep coupling with Character any more?
Last time I learn from the document, the reason putting RPCs into the character is to saving the overhead of net guid of CMC…
I wish the movement related stuff could be put back into the CMC itself,
leaving us a loose-coupled character.