The server is never locally controlled?

Hi guys,

I’m working on a multiplyer game for the VR Vive, so I followed tips from this site: Project Artemis: UE4 Multiplayer VR. But one part is failing.

When the server (which is also a client) check the “IsLocallyControlled” node, he never returns true. So he never send his position to the other clients but can see them moving around. I figured this out threw severous logs and print string. Is it normal? Am I missing something? Thanks for the answers guys. Cheers.

did you maybe figure this one out? I have the same problem:

if (World)
{
    if (IsLocallyControlled()) {
    	GEngine->AddOnScreenDebugMessage(-1, 7, FColor::Blue, TEXT("spawn light success"));
    	NoctovisorLight = World->SpawnActor<AAlienLightHolder>(AAlienLightHolder::StaticClass(), GetActorLocation(), GetActorRotation());
    }
}

executes on owning clients but not if the server is the owner

You probably want

if ( HasAuthority() || IsLocallyControlled() )

no, in the case of a client calling this, the spawning would execute on both the client and the server since both of them pass the if statement

Ah, right. My mistake, what you want to check for is the NetMode and see if it’s the listen server as only the listen server can have a local client in addition to being the server.

if (GetNetMode() == ENetMode::NM_ListenServer || IsLocallyControlled() )

Unfortunately this produces the same effect as your previous proposition. I want the code to execute only on the calling controller. With this, if the client calls, the server AND the client execute it.

Ok so after hours of fighting i figured it out. You just can’t call this function on beginPlay, apparently the server needs some time to connect the player controllers, so just do it after a delay

1 Like