How to set a blueprint to fire Only when both players have connected.

What i’m doing:
Setting a Shared camera for 2 players using a listen server.

The Problem:
I’m referencing the players on begin play so the camera can calculate its position and rotation. I can’t seem to get the camera’s logic to fire when the players are both on the server. The camera will fire its logic before the second player connects, which makes the camera work incorrectly on the host side. How can i Setup the camera so it will fire the logic only when both players have connected?

What i’ve tried

  1. Spawning the Camera seperatly in the gamemode, this worked somewhat but only with adding delays which are not an optimal choice. This also caused more problems considering the players movement is using the cameras rotation. I tried moving the camera spawn logic from event onpostlogin and event begin play, which made little difference.
  2. Throwing the bp in the level and setting it from the level blueprint. This seemed to work well in editor, but in a standalone game the host wouldn’t set the camera correctly.
  3. Spawning in the levelblueprint, caused mostly similar issues to spawning in the gamemode.
  4. Checking the gamemode playercontroller variable and the gamestate player array if they are equal to the amount max amount of players. This didn’t fix the problem even though the check seemed to be working.

Any Help would be appreciated!
Have an awesome week.
-SamuelB

UPDATE:: I added an 8 second delay before the player referencing function in my camera, which seems to fix the issue. Obviously this is not an optimal way to fix the issue, because connection times can vary. Any suggestions are welcome ! =)

Hi SamuelB

I would create a BlueprintInterface and install it in the cameraBP. On beginPlay in the character Blueprint you can call a function from your BPInterface as a message. This would fire as soon as the player is spawned.

So in your cameraBP you should fire your logic when the InterfaceCall happend two times (one for each player)

Here is a link to the documentation of BlueprintInterfaces (I think they are awesome)

Cheers,

Evil_Fischi

Hey thanks for the answer! I’m not too familiar with interfaces, so i guess its time to learn something new. I’ll give it a try and report back.
-Samuelb

I would recommend to get to used to them, I use them so often by now. They are very helpful :wink:

Looks like interfaces are more important than i thought, its working ! Thank you so much for the help =)!

How i Implemented the fix: I Made an interface, added it to my camerabp. Created a Interface event that increments an int variable when a message is received. When the int is equal to 2 it fires the set player reference function.

**Quick follow up question: ** would it be smart to implement a round start counter using the same interface method? When each player has been initialized the round start counter would know when to start for example?

-SamuelB

yes it would be the same logic.

Ok, thanks again! Looks like i got some code to redo =).