Custom Event 'Run on Server' does not work

Hi,
for an online RTS I am trying to Spawn Buildings.

In my ‘PlayerController’ I spawn an Actor from type ‘ConstructionManager’ with the PlayerController as its owner.

On ‘BeginPlay’ of the ‘ConstructionManager’ I do ‘EnableInput’ for it with its owning ‘PlayerController’ as input source.
When pressing ‘H’ the ‘ConstructionManager’ should call a CustomEvent with ‘Run on Server’, which should then execute a ‘Spawn Actor of type’ Building.

But the CustomEvent never triggers.
In the docs it says

4.If the RPC is being called from client to be executed on the server,
the client must own the Actor that the
RPC is being called on.

So what exactly is meant with owning? As i said my ‘ConstructionManager’ is owned by ‘PlayerController’ isn’t this enough?

I figured it out by myself.
If you want to use a CustomEvent(replicated by server) you have to make sure that the Blueprint is only spawned on the server and then replicated. So you have to use an “AuthoritySwitch” and plug the Blueprint to “Authority”.

If you don’t explicity spawn (in my case) “ConstructionManager” on server with the “AuthoritySwitch” it will be spawned on the client and the server. The server then replicates it to client which means you do have to copys of “ConstructionManager” on the client then. The problem is that the original version of the “ConstructionManager” on the Client gets priority and does not have a verison on the server. So it is not able to Call a Function on the Server.

To put in in a nutshell:

If you want a Blueprint to be able to perform “CustomEvents” with “Replicate on Server” you have to make sure that it is only spawned on server. Do this with an “AuthoritySwitch” before Spawning it. Then make sure to set “Replicates” in the Blueprint settings.

For more details see:
http://cedric.bnslv.de/Downloads/UE4_Network_Compendium_by_Cedric_eXi_Neukirchen.pdf

Hey broskies, your link to the pdf is dead.

this should work

Hi,

what do you mean with “Span Blueprint only on Server”? I have the exact same problem here: I have put a blueprint in the scene, which has a light and a boc collision. When a player enters the box, it can press “E” to switch the light on and off. The problem is, that it is only visible on the client and my custom event, that should execute on the server just dont work.

SOLUTION:

The Problem was, that in this moment, when I enabled the input, the blueprint was kind of running on the client. But when I said RPC->Run on Server, this doesnt work, because the blueprint itself IS (!) running on the server and the command wasnt executed. So the solution is, to Own the Actor, the blueprint is running on, by the player character and then execute an RPC-run on server. I hope this helps

1 Like