Hello, i have an issue i can’t seem to resolve.
I have weapons that damage and simulate physics on enemies.
Now when the enemy is getting hit (falls over and is simulating physics) but is not dead, i want the enemy to stand up and attack the player again (after a short delay/animation). I got this to work after following some tutorials.
Now, my problem is, that when the enemy is dead (do mind, that i have a delay of 10 seconds before i destroy the enemy actor for realism reasons), it still triggers my ‘restore enemy’ function and the ‘dead enemy’ is chasing me for 10 seconds and then dissapears. Does anyone know of a solution for this problem? I tried to make a boolean with ‘is dead’ and to check for it’s health, but both don’t seem to work.
Can i give the ‘dead enemy mesh’ some function or variable, which i can then use for a condition to not let the dead enemy trigger my restore enemy function?
Hmm. This does seem like it should do as you say. Have you tried using PrintStrings throughout for debugging? maybe do a printstring after you Set Health of your Health value, and one after you set “Is Dead” to make sure that’s absolutely happening. You could also try using a Gate node, that closes as part of the “Health = 0” branch, and would be located between the “Tick” and “Is Simulating Physics” node.
Thanks a lot for the feedback! I really appreciate it, cause i’ve been stuck with this for some time now haha…
I have been debugging and the set health is 100 on spawn (also shown on print string when the enemy spawns), and when i hit it for 100, it shows ‘true’ for the ‘is dead’ print string. So now i finally know that the issue wasn’t there!
In my game i spawnmultiple enemies from the same blue-print. Every 5 second a new enemy spawns. Now i did a print string after “Event tick-> If health = 0 branch” for both the true and false. The rest i disconnected just to see what was gonna happen.
So it starts out with getting only False print strings. When the second enemy spawned it continued the False strings.
But when i killed one enemy it started showing False-True-False-True etc etc. So i think ‘multiple enemies’ is what messes things up. Maybe the tick is getting both false and true’s at that point and because of that it continues tries to bring back ‘all’ meshes that are simulated at that point, including the ‘dead enemies’?
I tried it again by spawning only one enemy and there it all seems to work perfectly fine!
The enemy was getting up when shot - but not killed, and stayed on the ground when it was killed.
I tried using the Gate node like you said, but i am kinda new to all of this and haven’t used a Gate node yet. I’ll post what i tried, but i think it’s not what you meant / how a gate node works haha
Do you have any ideas to fix this? Like i said, the problem lies with multiple enemies on screen… as the blueprint seems to be doing exactly what i want with only one enemy spawned.
So disregard the gate, because we know the problem is somewhere involving multiple BP’s. So all BPs of this type are getting the respawn code. Can you show the entire code on tick? Including the Calculate Mesh Location event and any other condensed code/events called?
Probably you have to configure the logic of behaviors about the enemy pawn. Simply setting the mesh doesn’t solve the problem because your pawn is still controlled using the previous AI.
Usually mesh is just an apperance of the pawn. If it inherits character, what really works is the root capsule component. If only the mesh “dies”, the capsule component is still working.
To make a pawn “dead”, I recommend to detach the AI controller. After detachment, the uncontrolled pawn performs just like a normal actor. Then you can start simulating physics on it. But please consider 1)the capsule may make simulation wrong if it’s a character; 2) the detached AI controller should be destroyed or recycled manually.
If an AI controller is still needed for the dead enemy, define a task “die” on the AI and execute it on death. You can also additionally set the pawn’s speed zero on death to further ensure the dead enemy not moving.
Putting a ‘detach from controller pending destroy’ on the ‘dead enemy’ seemed to have fixed it! The simulate physics still work, though the dead bodies only seem to linger for a few seconds instead of 10 seconds, but that is fine for my project!
I am not 100% sure what you mean with the detached ai controller should be destroyed or mannually recycled. I can’t seem to destroy it? Or at least i don’t know how to destroy it… I use the Spawn Default Controller on Event BeginPlay. It doesn’t seem to affect anything, so should i bother? Can it mess up future things?
Anyhow, i wanna thank the both of you for helping me and giving me advise/solutions! Much appreciated!