Im trying to make the death and respawn system with a damage and health bar system but when the health goes to zero the actor is destroyed but it doesnt respawn and gives me this error…
Hey @RodericDarkwell
your functions are either using a Bind in your widget or the EventTick. These functions get executed every tick (!). So when you destroy your actor which is still referenced you have overlapping events. Trying to get informations from the referenced actor and trying to destroy the referenced actor. By using DestroyActor your referenced actor is a PendingKill thus not available for retrieving informations and causing your error messages. In your case the reference of your character should be changed when you spawn the new actor.
What you could do (my personal opinion):
- Do not use Bindings in your widgets. Execute an event when your health / mana / rage has changed to set the corresponding values in your widget. So instead of trying to get the information every tick you send the informations once when it changed.
- Do not use EventTick if you don’t have to. Here you could combine your functions. E.g. HealthChanged => Set Health in your widget => Check If Health <= 0 => Respawn
Respawn => SpawnActor => Set Health from new Character => HealthChanged - Here you used the LevelBlueprint for your events. It could be worth trying to redesign this with using GameMode and/or PlayerController/PlayerCharacter. GameMode would handle Spawning your Actor on Start and Respawn, handle different checkpoints/goals in the level. Your PlayerController/PlayerCharacter could handle the widget interaction / communication.
427_WidgetCommunication.zip (1.4 MB)
Hi thanks for the help, I tried to replicate what u did and besides not being able to resolve the problem now my health bar doesnt even move when the actor gets damaged…
Thank you so much for giving me a real project example for the subject but being an amateur I may or not have made worse…
You can show pictures or upload your project. Do you need explanations for the example project?
- We start with the MainMenu map which has no extra GameMode or PlayerController Or PlayerCharacter, everything is default. Here we create the WBP_MainMenu widget inside the level blueprint.
We create the widget, add it to the viewport and tell our game that only the UI responds to user input. - Inside our WBP_MainMenu widget we only have 1 button.
This button has a OnClicked function. So when we click it this will be executed:
It will open our other map ShowCase - Inside the level blueprint of ShowCase we tell the game that the player controller should respond to our user input (InputActions)
- This map has a GameMode called BP_PlayGameMode, a PlayerController called BP_PlayController and a Character called BP_PlayCharacter.
These settigns can be changed by opening the GameMode blueprint or inside the WorldSettings of the map. So when this map gets loaded the BP_PlayGameMode is used. Our BP_PlayController and BP_PlayCharacter are spawned at the beginning. - The first event gets executed inside the BP_PlayController.
On EventBeginPlay execute the CustomEvent called CreateHUD.
Here we first check if the HUDRef is valid. You can drag the variable from the variables list into the EventGraph, use Get and with a right click on the Get convert it to a validated Get.
If this variable is valid (it was previously set and not empty) we can just add the widget to the viewport. If this variable is not valid we create the widget WBP_HUD, set our variable HudRef and then ada it to the viewport. So when we start the game on this map, the variable will first be empty and invalid. Would we call this event again later on the variable would be set/valid from before and then just added to the viewport. After that we “speak” to our BP_PlayCharacter via a CastTo node and tell our character to execute Init -
BP_PlayerCharacter:
We execute the CustomEvent Init. The Init functions calls 3 other events called CreateRef, HealthChanged and ManaChanged.
The CreateRef event just creates a reference to our PlayerController so we can use it later on.
HealthChanged uses the ControllerRef so we can acces the Hud. Here we send our Health to the widget via SetHealth. The Health can be changed with an already included function called EventAnyDamage. Every time this event gets executed we call our HealthChanged event again.
At last in HealthChanged we check if our Health is equal to or below 0. If this is the case we execute the Dead event.
The Dead event just calls a CustomEvent inside the GameMode called Respawn.
ManaChanged uses the ControllerRef so we can acces the Hud. Here we send our Mana to the widget via SetMana. -
BP_PlayGameMode:
Inside the GameMode we just have the Respawn event. So when our character dies, we destroy the old character, spawn a new character at a random location, tell the PlayerController to take control of this character and execute Init in this new character. This means when a new character executes Init it will send its Health and Mana to our HUD and we can see both at 100 again. -
WBP_HUD:
These two functions will change the appearance of the two ProgressBars inside the widget. We divide Health and Mana by 100 because a ProgressBar only displays values from 0 to 1.
If you now want to test these functions inside the example project you can press 1 or 2 on your keyboard. These two keys will execute these events in the BP_PlayController:
1 will use the implemented ApplyDamage event and 2 will change the Mana by accessing the float variable from the Character and then change it and set it inside the Character. Then execute ManaChanged to display the value.
Thank you so much for the patiente… I was able to make the Widget to work again but theres just this thing… how to I say to the dead event that my health is below zero?? I replicated everything and still I dont seem to find a way to make my actor “die”…
My project is a little bit confusing at least for me…
For damaging the actor´s health i have a cube that deals damage when touched and thats working just fine with everything the only problem is when the actor gets to no health nothing happens and the health bar just stays empty
And this is the “death Cube” system I tried to make with your example
Sorry for so much replies but for some reason I couldnt put more pictures in one post…
You don’t call the Dead event after the branch. On the HealthChanged event you check if the float Health is equal or below 0. if this is TRUE call the Dead event.
I just did that and it resolved the issue but now when the actor respawns the health bar and the stamina dont move
It was the missing dead event like you said but now its this issue
Do you mean they don’t refill or don’t they change when you e.g. get damage?
I mean I respawn but everything still works, the only things that don´t are the health bar and stamina bar after respawning… and if I try to make the actor “die” again it working as expected but the bars dont move…
Before dying they are moving when getting damage or when the actor runs but after the respawn doesnt happen anymore…
You could try to add PrintString to some events to see which event gets executed. Does the example project work for you?
I don´t seem to be able to see the printstring logs… still I went to see the output logs and everything seems ok i dont know what I should do…
Everything is working expect the bars not moving after respawning…
How big is your project? Could you upload it?
How and where do you create the HUD in your project?
When you download the project from me and press play, does this work or do you have the same problem as in your project?
The HUD was created in a widget blueprint
My project is around 30 gb… to be honest I´m just a guy trying to make a souls like rpg game so I´m not that sure of what I am doing…
The project example that you gave me works exactly as the video actually
Unfortunatly even as a compressed file I can´t uploudit here…