BUG? Spawned Actors don't replicate blueprints correctly

Hey, I recently encountered a bug with spawning replicated actors. So what I have is blueprint below. A blank actor spawns a random trap from an array at begin play which is replicated to any clients, such that everyone sees that this trap is spawned. This works perfectly for when actor is placed directly into scene, but when spawned into scene, replication isn’t synchronized. Any clue why this happens?

This is a screenshot of blueprint inside my random trap actor. As you can see, it picks a class from an array variable inside blueprint, in this example, a cylinder or a cone blueprint class. All three blueprints, random trap class, cylinder class, and cone class all have “Replicates” box ticked.

Here’s a photo of traps being run in editor. bottom two are Random Traps placed directly into scene, and as you can see, are replicated to client correctly. upper one is spawned into scene through Level blueprint’s “Begin Play” node. In upper one, server only sees one trap, but client sees both, which I assume is because it spawned a random trap while it also replicated server’s trap.

Server

Client

Hi ,

Since RandomTrap blueprint exists both on Server and Client, this is being run twice on Server. First, Server instance of BP runs and spawns a random trap. Then Client instance asks Server to do same, at same position. That also explains why you see two different classes spawned: each time Event is run, it’s getting a random value for RandIndex.

You probably want to do this without Run on Server replication, and only fire event on Server. You can specify this by using Switch Has Authority node before calling Event:

68023-switchhasauthority.png

Hope that helps! Let me know if you have further questions.

Hey ,

Thank for quick response. Unfortunately, this didn’t fix problem. I changed it like you mentioned, and blueprint runs fine when random trap actor is placed into scene, but when spawned into scene using a “Spawn Actor from Class” node, same problem above happens, where both client, and server spawn separate traps, sometimes same one, sometimes different ones.

Ah, I apologize, I missed that part of your post. Can you show me which BP is spawning RandomTrap BP, and what BP setup is for that? Thanks!

No problem. BP that is running and being shown in original post is in project I sent you, in folder Blueprints\Traps, named “RandomTrap.” To reproduce bug, you simply need to spawn “RandomTrap” actor into scene using “Spawn Actor from Class” node, and using PIE editor’s 2 player feature. To see difference between two cases, you’ll need to place one “RandomTrap” directly into scene, and spawn other, and you’ll notice that placed trap replicates correctly, but spawned one runs it’s BP twice.

Right, but from where are you spawning it? Which BP? And are you limiting who spawns it to Server?

Oh, yeah. actors are being spawned in level blueprint. events go like this: “Event Begin Play” → “Switch has Authority” (from Authority node) → “Spawn Actor From Class”.

“Remote” node from “Switch has Authority” goes to nothing, so it’s just server spawning actor.

Hey again,

I tested this in a new map in your project, spawning RandomTrap into level from Level BP, using Event Begin Play and Switch Has Authority. I didn’t see same thing happen. This is setup in Level BP:

This works consistently for me, combined with following RandomTrap setup:

RandomTrap is set to Replicate, as are each of traps. I’m not seeing any variation between Server and Client. Can you repro this in a smaller test project for me and send that my way?

Hey ,

Thank you so much for your time in helping me with this. Unforunately, I’m currently unable to send you project until about this friday, but once I get chance to, I’ll try and see if there’s any differences between your setup and mine. I’ll let you know results by friday-ish, and if it’s still not fixed, I’ll send you project.

Sounds good, no rush. I’ll leave this post Resolved for now for tracking purposes, but reply when you have time and we’ll pick it up from there. Thanks!