# Major - Join In Progress Has Multiple Issues

**URL:** <https://forums.unrealengine.com/t/major-join-in-progress-has-multiple-issues/876343>\
**Category:** Issues and Bug Reporting\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, bug-report, fortnite\
**Created:** [April 7, 2023, 10:35pm UTC](https://forums.unrealengine.com/t/major-join-in-progress-has-multiple-issues/876343 "2023-04-07T22:35:16Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![LionUnchained](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/lionunchained/32/1039015_2.png) [@LionUnchained](https://forums.unrealengine.com/u/LionUnchained)\
**Post date:** [July 23, 2024, 3:30am UTC](https://forums.unrealengine.com/t/major-join-in-progress-has-multiple-issues/876343/25 "2024-07-23T03:30:43Z")

</div>

> **TL;DR**
>
> ```auto
> ValidatePlayer<private>(Agent:agent)<suspends>:void=
> TimeoutPeriod:float=180.0
> race:
> block:
> loop:
> if(Player:=player[Agent],Player.IsActive[]):
> HandleValidPlayer(Player)
> break
> else:
> Sleep(0.33) 
> block:
> Sleep(TimeoutPeriod)
> Print("Warning: ValidatePlayer: Timeout")
> 
> ```

I have a proposed solution to this issue as well as supportive reasoning and a really nice infographic for you all today.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/7/2c7a2187136b7ea36f07a3f6c9d0d74086d3e978.jpeg)

Essentially what is happening is that Epic has been focused on getting players into the game fast and that means that asynchronous sub processes of the Player Joins process can complete as quickly as possible, but this sanic speed optimization comes at a price.  
A player controller, agent, camera, eta are being prepared in parallel to a player initializing over the network, and it seems that can all complete and get passed along with a reference to the Player through the Player Joined Playspace function for handling BUT without the player object _actually_ being valid. 🙀

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/9/e/a9ec6b7a899dbe9087bf76f2e5b5fdf7ebf6c823.png)

This implies inheritance from Agent which is the super of Player, which in laymens terms means its a package deal. What happens to Player must also happen to Agent. As such, you’ll notice that you’ll also get spawned triggers from player spawners passing the agent before its ready:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/7/8/678d9e261a417a4c5a84940fac822b6b533f5b38.png)

> Where the error occurs is that the Player and Agent in these cases aren’t valid.

… Or  
If you would please put on your tinfoil hat as a safety precaution for this next part…  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/c/28c09f889571f68b90181c895483f7048157286f.png) we may proceed.  
rather, my presumption is that they are actually placeholder objects which allow Epic to pass `fake` dependencies into initialization processes and swap them out with the real deal to optimize load times.  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/d/61d72d439969fcde3eb9074f71dfe76f4d3cb720.png)  
You may now remove your tinfoil hats… 🫡… thank you.

So onto the tangible results of what this all means:

# The Problem:
Invalid Player and Agent references are passed through Epics hacky initialization process into devices in the game allowing invalid Player/Agent references to attempt to be used prior to them being ready for use.
# The Solution:
A player validation loop that ensures that the Player/Agent that you're referencing and hope to pass along into subsequent functions is actually going to work before you pass it.

```auto
    ValidatePlayer<private>(Agent:agent)<suspends>:void=
        TimeoutPeriod:float=180.0 # <- Time (seconds) before we abandon
        Interval:float=0.33 # <- Time (s) between attempts
        race: # <- race means whichever of the next 2 blocks finishes
              # first reigns supreme and the other is cancelled
            block: # <- Block 1 in the race
                loop:
                    if:
                        Player:=player[Agent] # <- Cast to player
                        Player.IsActive[] # <- Confirm player is active
                    then: # <- On Successful IsActive check
                        HandleValidPlayer(Player) # <- Pass them onto init
                        break # <- Break the loop
                    else: # <- On Failed IsActive check
                        Sleep(Interval) # <- See top: Interval
            block: # <- Block 2 in the race
                Sleep(TimeoutPeriod) # <- See top: TimeoutPeriod
                Print("Warning! ValidatePlayer: Timeout") # <- Logging

```

> **Without Comments / Scoping / Const Declarations**
>
> ```auto
> ValidatePlayer(Agent:agent)<suspends>:void=
> race:
> block:
> loop:
> if(Player:=player[Agent],Player.IsActive[]):
> HandleValidPlayer(Player)
> break
> else:
> Sleep(0.33)
> block:
> Sleep(180.0)
> 
> ```

## In Summary:
By passing players from the server join event or player spawner event into a validation function prior to forwarding them through any other initialization we can compensate for Epic's OSHA violat- "safety circumvention" so our players can enjoy the load time optimizations without simultaneously breaking our game logic or player init flow.

> What this might look like in practice:

```auto
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Fortnite.com/Playspaces }

game_manager:=class(creative_device):
    @editable
    Spawners:[]player_spawner_device=array{}

    OnBegin<override>()<suspends>:void=
        for(Player:GetPlayspace().GetPlayers()):
            ValidatePlayer(Player)
            spawn. OnPlayerJoined()
        for(Spawner:Spawners):
            spawn. OnPlayerSpawned(Spawner)

    # Player Spawner Variation
    OnPlayerSpawned(Spawner:player_spawner_device)<suspends>:void=
        loop:
            Agent:=Spawner.SpawnedEvent.Await()
            spawn. ValidatePlayer(Agent)

    # Playspace Joined Variation
    OnPlayerJoined()<suspends>:void=
        loop:
            Player:=GetPlayspace().PlayerAddedEvent().Await()
            spawn. ValidatePlayer(Player)

    ValidatePlayer(Agent:agent)<suspends>:void=
        race:
            block:
                loop:
                    if(Player:=player[Agent],Player.IsActive[]):
                        HandleValidPlayer(Player)
                        break
                    else:
                        Sleep(0.33)
            block:
                Sleep(180.0)

    HandleValidPlayer(Player:player):void=
        block:
        # This is where your normal initialization would go
        # Aka make your custom player, map it, etc

```

**PS:**  
Please note that any Epic internal processes related to players being added to ongoing games in between rounds or at other inappropriate times for the game are outside of our control for as long as we use their broken systems. Unfortunately there is no way to prevent these issues outside of not using their premade round system, and creating custom initialization and player handling wherever possible. Yes, this may mean creating your own custom round system.

Also note that if you set Join in Progress to Spectator epic spawns and immediately eliminates your fort\_char which will trigger your listeners to begin initialization. Without additional validation checks such as `Player.IsActive[]` or `FortCharacter.IsActive[]` this can lead to failed or partially failed initialization.

---

_[View the full topic](https://forums.unrealengine.com/t/major-join-in-progress-has-multiple-issues/876343)._
