Multiplayer - Actor Spawning on Server & Value Setting on Client

Ok, so I have a question. In my player controller, I am attempting to spawn a “sidekick” actor and then set a blackboard value so that the sidekick will follow around the player’s pawn. I want this to work on multiplayer, so that each player can have their own sidekick.

However, I am sort of struggling with the execution of this. I know that the actor has to be spawned by the server, but I also need some of the stuff that comes after the spawning to be executed on the client.

So what should the flow look like here? Right now, the client calls a Server replicated UFunction which spawns the actor and sets some values. But in this scenario the two clients aren’t receiving some of the info. If I turn that UFunction to NetMulticast, then there are some issues with the server spawning the actor but the clients not having access to it yet. Any help here would be greatly appreciated! Thank you!

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.