How to check everything before start the game? (Multiplayer)

This is my desperate attempt to check that everything has been loaded correctly.

Check the pawn components have been instantiated successfully.

Check all players, their pawns, and the world.

So… I know this is not the correct way to do it.
But I haven’t found another better way to do this.

Can someone light the way?
If you share your code it would be wonderful…
A couple of screenshots would be enough.
Thank you very much!!

Nobody use this code in your project. I think that was responsible for almost i losing my entire project.

You have an authority check before the “wait for pawn ready” validation. So I guess this code is running on the server? If so, this doesn’t make any sense lol. There is no replication or any network delay on server side.

IMO each actor should be responsible for waiting necessary values / initial replication on their own. What I did for my plugin was create a basic “wait initial replication” system. It looks something like this:

  1. In your actor’s BeginPlay for example, call your custom WaitInitialReplication function.
  2. WaitInitialReplication function continuously calls IsInitialReplicationComplete via a timer.
  3. IsInitialReplicationComplete is an overridable function that returns either true or false. Actors can override this function to basically make a list validation checks for themselves. This is all happening locally!
  4. When IsInitialReplicationComplete returns true, I call a custom OnInitialized event.
  5. Now I can do any actor specific initalization in OnInitialized.
1 Like

Hi STRiFE.x
Thank you very much for sharing your method.
I’m going to try it.

Yes, I think I did it in the worst possible way.

My idea was all the pawns to notify the GameState through the PlayerState when they would be ready. And then start the game. (the last code was in the PlayerState, this was the file that was corrupted). The strange thing is that I tried it for several hours and it worked correctly until the editor crashed… And from that moment no other blueprint could be edited… it was a terrible experience. Fortunately everything worked again to remove this file.

I will follow your instructions.
You are the only person who has given light to illuminate this path.
I am very grateful to you.

I’ll let you know how it turned out for me.

Thank you so much!!

1 Like

Hi STRiFE.x
I did it like this because the

IsInitialReplicationComplete

event no longer exists in UE5. Then i replace it with an interface function. It seems to work correctly.

But I have some doubts about the way to validate the components. Because I’m using the same Pawn for the players and for the AI.

Players use the HUD and the PlayerController
And the AIs don’t use HUD and use AIController…

So i did it like this:

What do you think about it?
Is it correct to do this to differentiate between a player and an AI? Or do you think there is a more correct way to do it?

Thank you very much!!

I’m not 100% sure if what I’m about to suggest is correct, but if a PlayerState starts BeginPlay and resolves the Cast to PawnCharacter(IsValid), you can clear and invalidate the timer by handle. And then proceed with other functions. Executed inside the PlayerState.
AI doesn’t have a PlayerState.

1 Like

I was thinking for the AIs to communicate directly with GameState since certainly the AIs don’t have PlayerState… GameState generates a Fake PlayerID for the AIs… this works for me perfectly for the scoring system. It only worries me that the pawn components do not load correctly in all their replicas since this could cause a null reference or that it does not load the skin correctly. At the moment the Casting to playerController when it’s an AI fails and that’s good… I just want to make sure that it’s the correct way to do it.

Thanks for your reply!!

when you look at the 5 minute mark at the chart in the video, you can see that the Pawn and Controller are resolved separately(different branches). That’s what’s to keep in mind. When a pawn has a valid character, the HUD(in the controller part) might not have a valid reference of the character. Atleast that’s how I understood it. It’s almost like two separate top levels.

1 Like

A great tutorial. Thank you very much for sharing.

I see it that way… The controller and the HUD exist before the Pawn…

1

Then the controller possesses the pawn.

2

In fact no pawn is needed… An example is the controller for the Lobby.

I think the problem is that the components take time to load. Especially the widgets seem to be very heavy.

And the problem is that each computer is different, and you don’t know what is happening on the client side…

So you need a method to know that everything was loaded correctly on all clients.

And if a client doesn’t load correctly, you kick it out of the game. XD

Cheers!!

You should also look into SpawnActorDeferred

it helps to initialize values before begin play and construction.

1 Like

You rock!!
Thank you so much!! :heart: