Hi, I am a self-taught game programmer (Unity if you asked).
I have questions:
Is it that Verse work with con-current, so that every time I need to execute a block of code which involve Players, I need to check if it’s valid? Ex: I have a function to create Player UI. Please read comment in it
# check Player here is make sense, we can not sure if Player still valid
if (Player := player[Agent], PlayerUI := GetPlayerUI[Player]) {
# is it okay if I pass Player to CreateUI() -> CreateUI(Player) -> we sure that player is valid at this point
set MainCanvas = CreateUI()
PlayerUI.AddWidget(MainCanvas, player_ui_slot {InputMode:=ui_input_mode.All})
}
CreateUI():canvas={
# currently my code look like this, but is it reduntdant? should i just pass Player and start from this
AllPlayers := GetPlayspace().GetPlayers()
if (Player := AllPlayers[0]):
#do thing here
}
From the talk from Official channel, It mentioned that “Subscribe” is not best practice to use. Then, how about a UI widget “Subscribe” to action? I think it’s a default way to handle UI event? from my understand, he mentioned “Subscribe” in another context, Ex: Player “Subscribe” to Signal “Full Stamina” → is my understanding correct? if no, how to handle UI event without “subscribe”?
Here the link (around 29:00): https://www.youtube.com/watch?v=B3WiSgKXsrg&ab_channel=UnrealEngine
Your approach is not ideal, you can take a look at the VerseCommander template for an example on how do manage UI, there’s no official way of doing it though
There are a couple of videos I could suggest for you to watch:
This one has the code and supplements the one WarForge did.
As far as Subscribe vs Await goes, it reminds of the difference between using a Tick Event and an Event Dispatcher. One is running constantly and the other as the event happens. But it is one of those things to consider in context. At Unreal Fest, they just did a talk about myths in Unreal and one is that using a tick is bad. But the speaker said that’s not really true. It just depends on what you are asking the tick to do (the context). So unless the game is lagging or the subscription is really complex, I wouldn’t worry about it too much. It does make sense to make things event driven where possible, but it is also not the end of the world to use subscribe either. They wouldn’t have subscribe if it was so anti-performant. Just my thoughts.
In general, as far as your code goes, I think it is best to do what WarForge (Mark) says and use maps to pair and initialize things together, so there a loop could be checking for events and updates to the map, for instance, if someone is eliminated or spawns in. Generally, I think you want to initialize the player/agent references to whatever in a map as they spawn in on game start. And then just manage the map from there.