jssjogren
(Jarod Sjogren)
May 14, 2020, 2:39pm
3
anonymous_user_4842251e:
First you said the actor needs to spawn on the server then:
if (Role == ROLE_Authority)
{
// spawn the actor
}
since all clients need to see this actor, this actor must have
bReplicates = true;
in the constructor,
Second you said there are some stuff that is needed to be executed on the clients, to do this fill the
void ClassName::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
// fill this function with variables that can be updated during the game and make sure to replicate what is needed to save bandwidth
DOREPLIFETIME(…...);
}
At this point anything happens on the server can be seen by all clients but no client to server communication has been built yet, now use the replicated variables to do some stuff on clients
If a client need to tell server something then you need to use RPC, once it is done on the server make sure to replicate the necessary information to other clients to make them sync with this client
or use ReplicatedUsing specifier to do the syncing.
Hope that helped.
[USER=“3519559”]Ahmad Gon[/USER], that is really helpful, thank you! I do have one more question though. For this newly spawned actor, I am looking to swap out their default controller when they’re spawned. Would this swap need to be performed server-side, client-side, or both?
The issue that I’m having is that when I swap out the controller, I need to update some blackboard values.