OnPlayerAdded not called for first player

Please select what you are reporting on:

Unreal Editor for Fortnite

What Type of Bug are you experiencing?

Devices

Summary

My OnPlayerAdded event is not being called for my first player when I playtest.

I have a basic set up:

OnBeing():void=
GetPlayspace().PlayerAddedEvent().Subscribe(OnPlayerAdded)

OnPlayerAdded(Player: player): void =
Print(“OnPlayerAdded Hook Called”)

I never get any output when I first start the session. If a friend joins the session, I see it.

Steps to Reproduce

See above

Expected Result

I should see that my initial player joining triggers this hook.

Observed Result

This doesn’t get called

Platform(s)

Windows 11.

Running some updated tests, I’m seeing some really strange results.

For context, I’m running this in a solo session, there are no other players in the playspace.

# Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=
        Playspace := GetPlayspace()
        set AllPlayers = Playspace.GetPlayers()
        Playspace.PlayerAddedEvent().Subscribe(OnPlayerAdded)
        Print("Running on begin")
        Print(ToString(AllPlayers.Length))
        var PrevPlayer : ?player = false
        for (Player: AllPlayers):
            if (Player = PrevPlayer?):
                Print("Expected")
            Print("Add player to resource manager without hook")
            AddPlayerCustom(Player)
            set PrevPlayer = option{Player}
    OnPlayerAdded(Player: player) : void =
        Print("OnPlayerAdded Hook Called")
        set PlayerCount += 1
        # add player to resource manager
        AddPlayerCustom(Player)

I ran this under the assumption that maybe players present exactly at game start (which would be true for me in a uefn test session) aren’t picked up by the PlayerAddedEvent, since that is registered after I’ve already joined.

IF that’s the case, that makes sense, and I would expect to have to register the event for future players, and grab the current playspace and set the original players manually.

However, my output actually shows 2 players now in the playspace.

This is the output I get from this:


Running on begin
2
Add Player to resource manager without hook
Add player to resource manager without hook

Somehow my uefn session is picking up two players in the playspace. It’s also considering them unique players, otherwise that check in the for loop would have printed out “Expected”. Has anyone encountered this?

If you need to do smth for each player (SetupPlayer)

  1. Call SetupPlayer for all current players in playspace
    for (Player: Playspace.GetPlayers()):
    SetupPlayer(Player)

  2. Subscribe to PlayerAddedEvent
    Playspace.PlayerAddedEvent().Subscribe(SetupPlayer)

1 Like