So, I currently have a function that runs from the client as follows:
if (GetOwnerRole() < ROLE_Authority) {
currentBuild = GetWorld()->SpawnActor <ABuildable>(
WoodWall, location, rotation, FActorSpawnParameters{});
}
In the above situation, the wall spawns in the client but not in the server, which is what I expected.
I want to replace this with a server RPC, so that the actor spawns through the server’s execution rather than through the client. Then, the actor is set to replicate so it should spawn in both environments (from what I understand). I have set this up as follows:
if (GetOwnerRole() < ROLE_Authority) {
ServerSpawnBuilds(location, rotation);
}
void UBuildManagerComponent::ServerSpawnBuilds_Implementation (FVector location, FRotator rotation)
{
GEngine->AddOnScreenDebugMessage(-1, 15, FColor::Green, FString::Printf(TEXT("Client Tried To Spawn Actor Through Server Execution")));
currentBuild = GetWorld()->SpawnActor <ABuildable>(
WoodWall, location, rotation, FActorSpawnParameters{});
}
This doesn’t seem to work at all, since the walls are not spawned in both the server and client. What am I doing wrong?
I have this in the header file (in case it’s relevant):
UFUNCTION(Server, Reliable, WithValidation)
void ServerSpawnBuilds(FVector location, FRotator rotation);
P.S - I’m very new to UE4, please help!