When I add a canvas to a player, it works fine; when I add that same canvas to another player while the first one still has it, it’ll remove it from the first. I’m pretty sure this is an internal bug, but here is my code. I don’t even have any code that removes the widget, so I’m confused about how it could be removed.
I mean, that’s almost exactly what I did; I don’t ever need to remove the widget. I’ve copied and pasted that exactly, but I don’t know how this will differ from what I had before.
This did not fix my issue, two people still cannot have the same canvas at the same time. Once the second person is assigned it, it gets removed off the first.
Update: The buttons / text / whatever you use need to be defined inside the MakeCanvas() function because if they’re at the top of your script per the docs, they’re classed as global or shared and so they get “removed” as has been happening.
I successfully made a functionnal custom ui for multiple player, but I had to do a Work Around, because the system seem to lost the Focus of the first Created UI and Event when trying to delete the older UI don’t seem to work, so I had to recreate a second, third, fourth… UI in front of the older to made it work for multiplayer. Here is the Final code:
using { /Fortnite.com/Devices }
using { /Fortnite.com/UI }
using { /UnrealEngine.com/Temporary/SpatialMath }
using { /UnrealEngine.com/Temporary/UI }
using { /Verse.org/Simulation }
MakeGameUI<constructor><public>(InPlayer : agent) := game_ui:
MaybePlayer := option{InPlayer}
MaybePlayerUI := option{GetPlayerUI[player[InPlayer]]}
game_ui := class():
var MyCanvas<internal> : canvas = canvas{}
LapsCountWidget<internal> : button_loud = button_loud{}
MaybePlayer<internal> : ?agent = false
MaybePlayerUI<internal> : ?player_ui = false
LapsText<localizes>(NbLaps : int) : message = "Laps {NbLaps} of 10"
LapsTextDefaut<localizes>() : message = "No Lap !"
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))
RemoveAddGameUIToUI<public>() : void =
Print("Just before add UI")
if (PlayerUI := MaybePlayerUI?):
Print("Adding UI")
PlayerUI.AddWidget(MyCanvas)
Print("Initial Message")
UpdateInitialUI()
RefreshGameUI<public>(Points : int): void =
Print("Just before refresh UI")
if (PlayerUI := MaybePlayerUI?):
Print("Adding UI")
PlayerUI.AddWidget(MyCanvas)
Print("Set Total Points")
set TotalLaps = Points
Print("Number of Points: {Points}")
UpdateUI()