Switching actors in game deletes part of UI

Heres my issue. Hopefully, I provide enough info. I have one User Interface providing the health bar of both actors. For cannon 1 I have the health I cast to my character get the health and then for the other progress bar I cast to my tank ,when I am possessing my first cannon I show only the cannons health and not the tanks, then when i possess my tank i show only the tanks health not the cannons. It seems when i possess the tank it chooses not to show the cannons then of course the other way around.

I know im getting the health i need for each actor but for some reason, it wont show the other actors health when i possess another.

260321-4.png

your issue is that your trying to get the player character in each case but the player can only be possesing one character at a time. so when you posses the tank you are no longer possesing the cannon so if you get player character and cast to the cannon (picture 1) it will fail since the tank does not inherit from cannon.

your best bet will be to set a reference for each in the widget when the level starts so you wont need to rely on get player character.

Can you please show me an example? ive fiddled around and cant seem to get it correct

post your script for possessing the two characters since that will probably be the easiest place for you to get the needed references. also post where you are creating the widget so we have a reference to that as well.

it may be as simple as having two public variables in your character, then when the widget is created you pass the variables on to set a variable in the widget, then use the variable in the widget as the needed reference. but without knowing your code / setup i cant tell you to do X.

Hopefully, this helps this is in my level blueprint showing where i hit number 1 or 2 to possess a character then the other two photos are in my cannon 1 user interface where i have the health bars

I have both of the possessing of characters in one UI. Are you referring to making two totally separate blueprints for UIs one for character 1 and another for character 2?

it looks like your creating your widgets from the level bp which makes things pretty simple. theres a few things that are odd to me however, for example you are creating a new widget each time you posses a character which seems like a waste as your just recreating the same widget without destroying the previous one.

anyways assuming that you want to show the health bars for both characters at the same time heres what you’ll need to do. first in each widget create a variable and make its type character (or whatever class your tank/cannon is). next in your binding function “get Percent x” you need to delete the get player character node and replace it with the variable you created. the last thing we need to do is to set the variable to be a reference to the character you want to get the health of. go to where you are creating the widget and drag off the return value pin, then search for the variable your created earlier (set variableX) and use the set version. now take the reference you have to the character in the level and connect it to the pin labeled with your variable.

the pictures below show an example of whats mentioned here. the first picture shows the widget setup, note here in the bottom left the variable type is set to thirdpersoncharacter since thats the class of the character i want the health of. the second picture shows the level bp setup much like your but here im only creating the widget once and i added in the setting of the variable.

if you have other problems with this or this isnt where your issue lied let me know and ill see what i can do.