Spwan A actorBP in multiplayer by Event begin play

I want to spawn an actor by useing event Begin play in my character blueprint, It works fine in when I just have one player, but when I have 2or more player, the Spawn Actor From Class Function will run multible times. So if I have 2 players every time I start the game, it should spawn 2 Actors. but in real life,it spawn 4 Actors when I start the game.
What should I do to fix this problem?

1 Like

BeginPlay is ran on Server and Client for each players. You have 2 players so thats 4 server calls to spawn actors.

To fix your issue, add HasAuthority node and connect True connector (Server) to SpawnActor nodes.

Sorry, I seems not work.
When I have 2 players the Server calls 3 times
Here is my blue print

266975-20191302.png

Here’s what you want to do:

Note:

  • Don’t set the SpawnBall1 as Run on Server. Like I said above, for every number of players, BeginPlay will be called by number of Pawns the player sees. So 4 players = 16 calls! (4 from server, 12 from clients). If set to Run on Server, you’ll be spawning 7 on a 4 player game (4 from Server, 1 for each clients). On a 2 player game, you’ll spawn 3.

  • In the SpawnBall1 event, add SwitchHasAuthority so you’ll only spawn your actor if the call is from the Server. Client calls will ignore so you won’t see extra spawned actors.

1 Like

Thx for your fast reply, I tried your sollution, but there still have 3 calls

266989-20191304.png

Are you sure you only have 2 players and is not using a Dedicated Server?

Yes , I double checked. I only have 2 players and not using a dedicated server.

267001-20191305.png

And your SpawnABall is not RunOnServer right?

Yes, My spawnAball is not RunOnServer.
Sorry for the chinese, I should translate them

No worries. Try removing your SpawnABall event and instead connect BeginPlay to HasAuthority and SpawnClass directly like below:

267003-e4-not-runonserver.png

I still get 3 calls D:

That is weird, we’re getting 2 different results. Can you please try creating a new project and do the same thing (Print TEST on BeginPlay with HasAuthority). I’ll try a new project on my end as well and see the results.

UPDATE: I think I have an idea why. Do you happen to have put your Pawns/Characters in the level prior starting? If so, that is what’s causing the extra calls. Try removing your Pawn/Character from the level and let the Engine create them for you on Play. And if the spawn did not work, try to add PlayerStart or change your Character’s Spawn Collision Handling Method to Always Spawn, Ignore Collisions

you are right, I tried in a new project, I got 2 calls!
I will double check my origin project, thank you

I think I have an idea why. Do you happen to have put your Pawns/Characters in the level prior starting? If so, that is what’s causing the extra calls. Try removing your Pawn/Character from the level and let the Engine create them for you on Play. And if the spawn did not work, try to add PlayerStart or change your Character’s Spawn Collision Handling Method to Always Spawn, Ignore Collisions

Hi, Chyros, I double checked my gamemode blueprint, I find out I had a “Spawn The player with their selected character from the gameplay controller Function” will run when I start the game, I disconnected this function, then I got 2 calls when I start my game.
Thank you for your patient!

No problem. Glad to help. Good luck on your game.