"Event Begin Play" fires twice from default pawn class in multiplayer

Setting “Event Begin Play” to print “Hello” will result in Server: Hello, Server: Hello, Client1: Hello, Client1: Hello.

This is from a pawn blueprint I have set to be the default pawn in the game. Turning replication on/off doesn’t change anything.

Question: Why does it do that? Is there a way to make it fire only once on each machine?

Bonus question: from the default Player Controller it will print twice on the Server and once on the Client. Why?

Possible workaround: Use ‘do Once’-node right after the ‘Begin Play’ event:

thanks for the quick answer… however it still gets printed 4 times…

It prints it once for each pawn in the level. Which means it prints it twice on the server’s side and twice on the client’s side. if you had 3 players it would print it three times. The node doesn’t actually fire twice. It’s just that you have 2 pawns and they both fire.

As far as the bonus question goes, I think it is because the server has access to all Player Controllers while the clients only see their own Player Controller. But not 100% on that. I know that if you try with more players, the server will print for all the Player Controllers while the Clients only print once so…

Same problem here. I am following the Endless Runner tutorial and got stuck here: event Begin Play in RunGameMode (second video) is called twice. DoOnce also didn’t work.

try “get player pawn” with player number = 0. Branch on whether “self” equals player 0 ’ pawn. Then print. This should work.

Self → Is Locally Controlled → Branch

4 Likes

Similar issue. The blueprint on the screen doesn’t do anything while I run around with the pawn, even if I set the number of clients to 1. Its like I’m still not possessing the player one pawn. Where is the setting or how do I fix it?

This saved me from going insane.

You are playing Multiplayer.

You have 2 Pawns. You have two Machines.
Both Pawns execute their code on Both Machines.

This is why you get 4 Hello’s.

You can use the “Switch Has Authority” Macro to execute Things on the Server/Clients only

1 Like

This happens when Start players as Spectators is enabled in Game Mode

265243-annotation-2019-01-13-123533.jpg

your answer saved me man :slight_smile: 2021

Same her haha. I have been stuck on this problem for two days now… Thank you Socke81!!

This helped me too. And I switched from initiating some stuff in BeginPlay to instead use NotifyMatchStarted.

In case anyone else stumbles on this issue:

I solved this problem in code by checking in BeginPlay() (on an actor component) that GetOwnerRole() == ROLE_HasAuthority

I’m curious about the NotifyMatchedStarted solution posted above, but checking the role authority was a quick and easy fix for me, just starting to learn about multiplayer and replication.