Reseting character variabls after respawning

So I’m killing the player like the ue4 doc say but instead of a button kill I’m using a variable (when the variable hits zero player dies) but when I respawn the character in the way ue4 doc says after it respawns my variable don’t reset up is 0 and the messager says it has error on the casted refs and nothing works at that point.

What’s going on and how do I get this fixed any answers are greatly appreciated.

Use a “Destroy Actor” node after the health variable hits 0. If the character actor is not “destroyed” it’ll preserve the variables.

Is this variable inside the blueprint of the pawn that is killed, the Controller class that tells it what to do (which does NOT die with the pawn), or the Player State for that Controller (which can replicate over network) or somewhere else?

I have the script in the UI and the character and the controller. In the UI deals with crunching the numbers and when the hp variable hit zero I call the destroy actor in the ui and the controller has the respawn script.

Sorry I didn’t answer the main question the hp variable is in the character sorry about that.

I am using the “DestroyActor” node

I have not even touched the construction script

That’s interesting. How about setting the character’s health to its default value in it’s construction script? That way, when the actor spawns it’ll run that script and you’ll get around the problem.

Yeah, touch it :smiley: See if that solves the problem.

:confused: I have no further suggestions, though it should have worked. May I see your BP setup?

Are you setting the reference from a “Cast to” node? Maybe the case is that the cast is failing.
Which guide did you follow?

Ok I’ll try it

I tried it and it didn’t work

I just read the massage log again it say after kill it’s not reading the character ref properly in my ui.

It’s saying
“Blueprint Runtime error: Attempted to access sidescrollercharacter_78 via property character ref, but sidescrollercharacter_78 is pending kill from fuction” then say from branches and other node in it it word for word in the quotations

I’m casting then promoting to variable

In the character I have a cast that’s cast to the character and get the game mode as object the promoted to variable. One in the ui that is casting to the player and getting the player character as object. And one in the game mode casting to the character and getting the character as the object. And all are promoted to a variable after casted.

Okay. It is most likely the cast is failing. Can you test it? Btw you said you followed a ue4 docs guide, can you give the link to it?

https://www.google.com/url?sa=t&source=web&rct=j&url=https://docs.unrealengine.com/en-us/Gameplay/HowTo/RespawnPlayer/Blueprints&ved=2ahUKEwiRloiK0cfbAhXD64MKHR9hCR8QFjAAegQIBxAB&usg=AOvVaw3FCegWa6LOqh9suKIYD4tE here is the method of casting and the kill script

Thought about it but I couldn’t find an obvious problem. For what it’s worth, I can give some advices:

  • Scratch the project, follow the guide exacty, make sure it’s working.
  • Implement your own function(Health variable), test if it works.
  • Check your wiring, maybe you plugged something where it shouldn’t be.
  • Or use a different approach: Use the Level BP instead of game mode for respawning:

Clear the game mode’s event graph. Just edit the class defaults. Save. Create an isDead boolean in the characterBP, set it to true when the health is 0. Save. Go to LevelBP, cast to characterBP and get the isDead variable. Add a branch and from the true pin, spawn actor from class and possess.