How to pass health upon possession

Hello!
I have been working on this for days, and tried dozens of approaches and AnswerHub ideas. Currently, I can switch from a primary to secondary pawn, and back again. This is necessary for travel modes. However, I cannot find a way to transfer current health between the two. Once the former is destroyed, the new spawned pawn cannot inherit the current health float value, no matter how I do it.

I’ve tried casting current health onto the spawned pawn before possessing/destroying, or making the widget track the value and then retrieving it, but either the new pawn inherits a full bar, or an empty bar. It seems the value is resetting out when I possess, regardless of what has been done.

  1. I’m using an interface to track CurrentHealth and MaxHealth, and plotting them in the Health widget, as described in a few videos, including this one: - YouTube

  1. The progress bar is bound to a function called HealthPercent, which gets the Health value via the Interface:

  1. Damage is processed on the pawns with identical processes:

  1. I associated the Interface to the Health widget, and both pawns, but it doesn’t seem to make a difference.

Everything works for just one of the pawns - damage is taken on the bar, and death with destroy the actor. But how to get the CurrentHealth to move to a newly possessed pawn? Any hints or suggestions would be much appreciated!

As far as I know, you cannot store variables in interfaces, and since you already mentioned you are destroying the pawns on switching them, it makes me think you are not actually storing the remaining health value somewhere that doesn’t get deleted. That would make it obvious as to why you cannot update your current health values; they simply don’t exist anymore at that point.

I recommend storing the health variable somewhere like, say, the player controller. Then, on possession of a new pawn, you can update the newly possessed pawn’s remaining health with whatever you saved in the player controller.

If this doesn’t work, I would like to know where and how exactly you are switching the pawns, and how you add the widget UI to your pawns.

Unless I’m misunderstanding something here… shouldn’t you just be storing it as a variable in the controller that is set on unpossess and then sets the pawn on possess?

I have seen reference to storing things in the player controller, do you mean the custom controller BP I’m using, or alongside a cast with the object being GetPlayerController?

Update

I stored the CurrentHealth variable in my custom controller, and it works fine. You were right, the issue was that interfaces cannot store variables. Thank you!

I am using GetPlayerController for my possess, either direction. However, I put a CurrentHealth variable in my custom controller instead. I cast to it during damage to update it, and cast to it to get it’s value upon EventPlay. It now works in both directions.

First you need to set up the variables in your custom controller BP. You could even make some custom events that handle the entire possessing and unpossessing (and immediately use that to set your variables) while you are at it, but without those variables in the custom controller BP, you cannot do anything.

The GetPlayerController only gets a reference to the player controller class at the index you request it at (with the default, i.e. player, being 0). If you want to access anything from your custom controller BP, you will have to cast the result of GetPlayerController to whatever class you are using, otherwise you can only get the standard functionality present within the standard player controller class.