Trying to get a widget removed from the HUD upon a character’s death.
The game has two levels. First level is a main menu that thr clients can either host a new game instance and load the second level, or join the game instance that has been hosted. All other BP and variables replicate properly.
Currently, it only works for the client that starts the game instance. Subsequent clients that join do not work. Print String and Debug Sphere confirm the event is executing, and referencing the correct character actor. I am testing using Listen Sever, and it does not matter which client “hosts” the game instance, and which joins.
Here is the setup:
Character is possessed by an AI Controller BP. The AI Controller BP has a hard reference of the Character BP.
The Character BP has an event that successfully removes the widget when the unit is deselected. This event is called “Remove Unit From Selection”. It also has an “Is Alive?” boolean.
Here’s what I have:
AI Controller - When Character HP <1 run event “Remove Unit From Selection” via hard reference to Characyer BP.
(This works, but only on the “host” client)
I have found an alternative that works on all the clients, but it requires a loop in the Character BP that checks every 0.5 seconds whether the “Is Alive?” boolean is false. If it is, it triggers the same event. This is not a long term solution as the game is an RTS with potentially hundreds of characters.
If I can confirm via debug the event is running on the correct actor; why should it matter whether the AI Controller is triggering the event vs a loop originating in the character BP?
I honestly can’t say that I’m following. What I can say though is that the adding/removing of any widget is not intended/designed to replicate. It only effects the local player. If you want to add/remove a widget from any players screen then you need to make sure the piece of code that is doing this is running “locally”.
Also be careful with your terminology. You mentioned “…the client that starts the game…”. This is in fact the server, not a client. It’s important as it shapes the way you think of and address any networking/multiplayer issues.
I suspect what is going on is that the piece of code you have that decides that the character needs to be removed from the selection is happening/running on the server which is why it only works for the server. You need to communicate with the client that this deselection has happened. How you do that, of course, is dependent on your order of operations or logic flow for the life cycle of this AI character. This is basically what you accomplished with the tick solution. Tick is running on both the server and client version of the character. As you said, and I agree, this is not something that is necessary for tick as it can easily be turned into an event driven system. You just need to find the right place for that to event to occur. Maybe tapping into the OnDestroyed event in the character would work. That of course assumes you’re destroying the character when HP<1.
You are correct, replicate is not the proper terminology.
I am destroying the character, I will try your suggestion.
The reason I used the host/client terminology is that the game has two levels, one being a menu screen with two buttons. When testing I have 2 players running on a Listen Server net mode.
The Server can press the host button, or the local client can press it. Either one will start a game instance and load the second level where all game play takes place. Whichever of the two does not press host, can press “join” and will load and join the created game instance. I assume that is the correct terminology.
From there, regardless of who pressed host, all blueprints replicate properly when needed and all character respond to their assigned player.
The issue is that the widget removal works on whoever pressed the “Host” button but not the “joined”.
Of the two windows that open when testing, one says “server” and the other says “client”. But thats irrelevant for which will work properly. Only thing that matters is who presses host.
I do apologize for the confusion though, my understanding of server client relations is very fundemental.
Understood, just want to make sure we’re on the same page with what’s happening.
The only open question is whether or not OnDestroyed triggers on both server and client versions of the actor. I don’t have the editor in front of me to test. I believe it does but if it doesn’t then we’ll just need something that does…or create your own server to client event.
Destroy actor works well. But this removes the possibility of a death animation. Here is a visual of what I am doing. I’ll add it to the original post as well.