x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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? alt text

Product Version: UE 4.20
Tags:
2019130.png (135.5 kB)
more ▼

asked Jan 29 '19 at 04:58 PM in Blueprint Scripting

avatar image

windlox
35 1 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Jan 29 '19 at 05:36 PM

avatar image

Chyros
1.2k 8 4 8

avatar image windlox Jan 30 '19 at 12:57 PM

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

20191301.png (43.4 kB)
20191302.png (67.4 kB)
avatar image Chyros Jan 30 '19 at 01:50 PM

Here's what you want to do:

alt text

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.

avatar image windlox Jan 30 '19 at 02:07 PM

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

alt text

20191303.png (70.3 kB)
20191304.png (39.6 kB)
avatar image Chyros Jan 30 '19 at 02:12 PM

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

avatar image windlox Jan 30 '19 at 02:15 PM

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

20191305.png (32.1 kB)
avatar image Chyros Jan 30 '19 at 02:16 PM

And your SpawnABall is not RunOnServer right?

avatar image windlox Jan 30 '19 at 02:18 PM

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

avatar image Chyros Jan 30 '19 at 02:19 PM

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

alt text

avatar image windlox Jan 30 '19 at 02:24 PM

I still get 3 calls D:alt text

alt text

20191306.png (108.7 kB)
20191307.png (235.6 kB)
avatar image Chyros Jan 30 '19 at 02:28 PM

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

avatar image windlox Jan 30 '19 at 02:42 PM

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

20191308.png (1.7 MB)
avatar image Chyros Jan 30 '19 at 02:50 PM

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

avatar image windlox Jan 30 '19 at 02:56 PM

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!

avatar image Chyros Jan 30 '19 at 03:00 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question