I almost succeed to correct this problem. I had the same issue, when a second player log in it stole the UI from the last one who did it.
So I followed this tutorial :
Here’s my class code:
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Simulation }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
MakeGameUI<constructor><public>(InPlayer : agent) := game_ui:
MaybePlayer := option{InPlayer}
MaybePlayerUI := option{GetPlayerUI[player[InPlayer]]}
# A Verse-authored creative device that can be placed in a level
game_ui := class():
var MyCanvas<internal> : canvas = canvas{}
LapsCountWidget<internal> : button_loud = button_loud{}
MaybePlayer<internal> : ?agent = false
MaybePlayerUI<internal> : ?player_ui = false
ScoreManagerDevice<internal> : score_manager_device = score_manager_device{}
LapsText<localizes>(NbLaps : int) : message = "Laps {NbLaps} of 10"
LapsTextDefaut<localizes>() : message = "No Lap Started Yet !"
var TotalLaps<private> : int = 0
block:
set MyCanvas = canvas:
Slots := array:
canvas_slot:
Anchors := anchors{Minimum := vector2{X := 0.5, Y := 0.0}, Maximum := vector2{X := 0.5, Y := 0.0}}
Offsets := margin{Top := 100.0, Left := 0.0, Right := 0.0, Bottom := 0.0}
Alignment := vector2{X := 0.5, Y := 0.5}
SizeToContent := true
Widget := LapsCountWidget
UpdateInitialUI<private>(): void =
if (PlayerUI := MaybePlayerUI?):
LapsCountWidget.SetText(LapsTextDefaut())
UpdateUI<private>(): void =
if (PlayerUI := MaybePlayerUI?):
LapsCountWidget.SetText(LapsText(TotalLaps))
AddGameUIToUI<public>() : void =
if (PlayerUI := MaybePlayerUI?):
PlayerUI.AddWidget(MyCanvas)
UpdateInitialUI()
UpdateLapCount<public>(Points : int) : void =
set TotalLaps = Points
UpdateUI()
In my other file that track the game I have this code:
OnPlayerSpawn(InPlayer : agent) : void=
#Print("A player just spawned!")
if(PlayerLap := TotalOfLaps[InPlayer], Player := player[InPlayer]):
else if (Player := player[InPlayer]):
set GameUI = MakeGameUI(InPlayer)
if(set TotalOfLaps[Player] = 0):
GameUI.AddGameUIToUI()
HandleCheckpointCompleted(Agent:agent):void=
if (Player := player[Agent], LapOfPlayer = TotalOfLaps[Player]):
set LapOfPlayer = LapOfPlayer + 1
if (Player := player[Agent], set TotalOfLaps[Player] = LapOfPlayer):
GameUI.UpdateLapCount(LapOfPlayer)
With this code, every player have the custom UI, the only problem that it update only the one of the last player that Has spawn.
When I succeed to correct this problem, I’ll post the final result