RPCs on Level Actor not Called

Hello, I’ve got an actor that is placed in the level with a couple replicated functions defined:


UFUNCTION(Reliable, Server, WithValidation)
void ServerAddModifications(const FData& MyData);
virtual void ServerAddModifications_Implementation(const FData& MyData);
virtual bool ServerAddModifications_Validate(const FData& MyData) { return true; }  
UFUNCTION(Reliable, NetMulticast, WithValidation)
void ClientAddModifications(const FData& MyData);
virtual void ClientAddModifications_Implementation(const FData& MyData);
virtual bool ClientAddModifications_Validate(const FData& MyData) { return true; }

Nothing I can seem to do enables the clients’ invocations of ServerAddModifications to reach the server. ClientAddModifications always properly broadcasts the call to all the clients.

Since this is an actor spawned in the world, I’ve heard tell of having to set the owner, and/or override GetNetConnection. GetNetConnection is the closest I’ve come to get this working, but I hit another snag:


// What to put here???
if (GetWorld()->NetDriver->ClientConnections.Num())
	return GetWorld()->NetDriver->ClientConnections[0];
else
	return GetWorld()->NetDriver->ServerConnection;

As written, the server will receive invocations of the RPC from the first client. If switched to the second client’s connection, it will also work thusly. The same behavior applies if I try to grab any of the two replicated Player Controllers and use their connections.

Attempts at using SetOwner here have failed, I believe because Unreal keeps trying to replicate the value of Owner? Not sure if so, or where to place the call to SetOwner, or which player controller to use as the owner on the server (same issue).

Incidentally, nothing about the above changes if the actor is spawned. Only actors which have multiple instances on the server (such as PlayerControllers) work properly if there is more than one client, because there is more than one net connection for each client? I’m missing something here, any help would be appreciated!

Were you able to solve this? I’ve had this problem for a day now. I’m considering erasing my objects from the level and spawning them from somewhere else.

Never figured out how to solve the issue exactly, but I ended up working around it. The problem is only when the clients attempt to call a server function, and so I’ve routed all of these instances through the player controller. That is, my custom player controller type has an AddServerModifications function that actors can call into, which works just fine since there is a player controller for each client on the server.

In a way this almost makes sense from an architecture perspective. You shouldn’t be calling server update functions often, and for the most part the server should be managing most of the game logic and state, and replicating that to the clients. The cases where you do want the client to notify the server usually have to do with player input, so see if you can funnel all the use cases into “what the player inputted,” route that through the player controller, and have the server figure out what to do with that client input.