If I create a custom event in a BP’s main event graph, I can set its replication (not replicated, run on server, run on owning client, multicast). This same functionality does not seem to be available if you create a new function in the BP.
The end result is I need to create a custom event in the main event graph which has the desired replication and use that to call the created function. It’s very messy.
Has anyone else encountered this? Is there a way to do this properly?
You need to carefully watch who is owner of that event, also if blueprint EXISTS on server and all clients.
For eg Player Controller exists only on local client and on server, it DOES NOT exist on other clients. As result you cannot replicate your PlayerController event to another client.
So far only one blueprint that i found that exists on local client, server and other clients is “Player State”
There is some great PDF with all that stuff about multiplayer done by somebody from unreal slackers chat, i will post link if i find it. But if you do not see me linking it here soon go to unreal slackers and ask about multiplayer pdf.
Hi Nawrot,
I’m not sure we’re talking about the same thing here. Unfortunately, I’m at work at the moment and can’t screenshot stuff but … let me see if I can make do with google image search.
Ok so here there’s a custom event “Fire”. Currently, it is set to “Not Replicated”. Let’s say we change it to “Run on server” so that the server executes it.
Now if we have a reference to the BP_Laser_Weapon, we can call “Fire” and know it will be executed on the server.
However, if we delete the custom event and create a new function…
And call the new function “Fire”, then we get a reference to BP_Laser_Weapon and call the “Fire”, this function will be Not Replicated and there is no way to change that as far as I know. We can’t specify that this function is to be run only on the server or any other option.
The only way I’ve found to deal with this is to leave the custom event in the event graph and have it be set to “Run On Server” and have it call a function we created. That seems to be the only way to ensure that a created function is executed only on the server.
Hmm looks like it is quite possible that i am not getting this.
Anyway from what i read you are pushing limits of unreal here. That messing with names of events and functions is quite dangerous. Last time i did such stuff i got circular reference of 2 functions that ate my project, yes i was forced to start it from scratch.
So if you can stay away from this problem by setting different names for functions and events you should do it. Confusing unreal with same function names leads into troubles and makes project quite unstable. So if you can avoid it do not try your luck.
Personally i have naming convention for all non local events:
RPC_ for events run on server
DISPATCHER_ for dispatchers
MULTICAST_
and so on, precisely to make sure that unreal will not confuse different events.
Yeah, I think we’re still on different pages. Let me try another way…
In an actor’s blueprint, you can create custom events (by right clicking in the graph and typing “Custom Event”) and functions (by pressing the + in the side panel). Let’s say we called the custom event “CusEvent” and the function “Fnction”.
Both of these function similarly.
If, in another blueprint, you reference that actor and drag a pin from it you will see both “CusEvent” and “Fnction” available as options. Either can be selected to execute the code that exists on that actor.
The major difference is that I can select “CusEvent” in the actor blueprint and set it to “Run On Server”. I am not able to do this with “Fnction”. As far as I can tell, there is no way to set the replication of functions.
My workaround is to create a custom event, lets call it “ExecuteOnServer-Fnction”. I then set it to “Run On Server” and launch “Fnction” from there. In this regard, “Fnction” is now able to run only on the server. But it’s a messy way to go about this.
I do not want to have all of my script done in the main event graph so I have split lots of it off into functions but I keep needing to apply this workaround so I have a bunch of two-node code blocks in the event graph, all just receiving an execute call then executing a function on the server.
If that still wasn’t helpful (I know I am terrible at explaining stuff), let me use an example. I have a client connected to a server. The client has a character. When I press “E”, I want to destroy the character actor. But this “Destroy” needs to be done on the server, not just on the local client. And, for cleanliness, I want to have the “Destroy” take effect inside a function. How can this be accomplished?
I don’t think you can change function replication in similar way that you can change it for events.
This is the approach I’ve been using. I usually create separate Event Graph for these RunOnServer events that just call a function so they don’t clutter my “main” Event Graph.
I agree, I think the main reason is (based on docs and forum threads) that functions meant to be returned immediately while events can have latent actions such as delays or RPCs (but can’t return anything in exhange). Since RPCs take time they cannot be invoked from a function. At least this is how I understand it.