Client RPC handles earlier than BeginPlay[updated]
I got strange behavior in my class. I spawn actor instance of my class on server by calling ServerRPC function from client. Server spawns actor with client as owner. Next, Server calls ClientRPC on spawned actor (need to say that actor have bReplicates = true; and bAlwaysRelevant = true; in constructor).
So actor is replicated to client and there is called ClientRPC_Implementation. First time all works fine, but that's all. Second and next actors wont properly execute ClientRPC (because there is condition with IsValid() check, that checks property, which would be set in BeginPlay).
I attached VS to game instance and found that for some reasons ClientRPC on client-side is called earlier than BeginPlay(on 2nd+ spawned actor), but first spawned actor have done work properly.
Anybody can reproduce this behavior? Or maybe I missed something then give me right point to see. Thanks in advance
UPDATE: Okay, as nobody answers I made little sample(in 4.11.p3 already). That's log which I receive:
That log I received on both: client and server instance(here in PIE, in my other project I received this behavior in standalone application). As you can see from 5th line, Client_RPC began occur earlier than BeginPlay(be care here are 2 different actors that writes to log)
Here's source files for project. If someone says how to upload whole project that it will take less than 5 MB then I can upload whole project.
It seems for me like a bug. Now can anybody give me some kind of answer, is it right flow of spawning and replicating actor or not?
After further investigation I have entered a bug report (UE-26811) to investigate why the ClientRPC function is being called before BeginPlay.
answered Feb 11 '16 at 06:00 PM
So I was having a similar problem, and I think it's a bug in
It should really be calling PostNetInit immediately after any Initial bunches have been dispatched and before any further bunches are processed, it also looks like it's passing in
I tried moving the init call to inside the loop at the end, but that assumes that there's always exactly one initial replication bunch.
Edit: This was a bit of a necropost so I created a new question on UDN.
I am experiencing the exact same on my project. 1.) I spawn an actor on the server in a blueprint. 2.) Immediately after, i call a multicast RPC from blueprint. The RPC itself is implemented in C++.
First actor: Actor gets replicated, BeginPlay executes, RPC executes.
Second actor: Actor gets replicated, RPC executes, crash because RPC uses data initialized in BeginEvent.
Time between spawning of actors doesn't matters. Happens 100% of tries.
I worked around it by having a BeginPlayCalled property, which is set to true at the end of BeginPlay and all client RPC's check for this variable and if false, add the RPC to a event buffer and return out. The event buffer is executed at the end of BeginPlay. This fixes it reliably, but is quite some extra work.
I need some time to isolate code to have a project to replicate this behavior. Just a heads up that thiis problem is still existing as of 4.21.1 and "quick" workaround to get your project to work in multiplayer.
Follow this question
Once you sign in you will be able to subscribe for any updates here